Combining Lists and Tupels
Batista, Facundo
FBatista at uniFON.com.ar
Thu May 22 09:18:41 EDT 2003
#- Hello,
#-
#- for an exercise I have to programm a python script
#- which sorts name, family names and addresses from a csv-File.
#- The csv-File looks like this:
#-
#- familyname;name;street;house-number;town-code;town
#-
#- I did it like this:
#-
#- f=open("test.csv")
#-
#- try:
#- while 1:
#- currentline=f.readline()
#- data=string.split(currentline, ";")
#-
#- address=data[2], data[3], data[4]
#- list[i]=data[0], data[1], address
#- i+=1
#- finally:
#- print "test error"
You're not thinking in a Python way.
f = file("test.csv")
list = []
for currentline in f:
data = currentline.split()
address = (data[2], data[3], data[4])
list.append((data[0], data[1], address))
Pay attention to the double (( and )) in the append.
Sometimes the ( and ) are optional when you construct a tuple, but it's
recomended not to skip them.
. Facundo
More information about the Python-list
mailing list