リスト周りのテスト

とりあえずリスト周りをチェックしながら文法に慣れてみる。

# test python
import types
print "=== test python : list ==="
## The list.
list = [ 1.0, 1.2, 0.0 ]
print type(list) #=> <type 'list'>
print len(list)  #=> 3
print list       #=> [1.0, 1.2, 0.0]

## The lists in the list.
listlist = [ list, [3.0, 4.0], "abc" ]
print type(listlist) #=> <type 'list'>
print len(listlist)  #=> 3
print listlist       #=> [[1.0, 1.2, 0.0], [3.0, 4.0], 'abc']

print type(listlist[0]) #=> <type 'list'>
print len(listlist[0])  #=> 3
print listlist[0]       #=> [1.0, 1.2, 0.0]

print type(listlist[0][1]) #=> <type 'float'>
print listlist[0][1]       #=> 1.2

## traverse the lists.
for vv in listlist:
	if type(vv) == types.ListType:
		print type(vv), vv, len(vv)
		for v in vv:
			print " %s\t%s" % (type(v), v)
	else:
		print type(vv), vv
# for文以下は以下のように出力されます.
#<type 'list'> [1.0, 1.2, 0.0] 3
# <type 'float'>	1.0
# <type 'float'>	1.2
# <type 'float'>	0.0
#<type 'list'> [3.0, 4.0] 2
# <type 'float'>	3.0
# <type 'float'>	4.0
#<type 'str'> abc

気になる構文