[Tutor] help on dic creation
Dave Angel
d at davea.name
Tue Nov 6 15:16:41 CET 2012
On 11/06/2012 09:01 AM, Mark Lawrence wrote:
> On 31/10/2012 01:01, Brayden Zhao wrote:
>
>> def fieldict(filename):
>> D={}
>> with open(filename) as FileObject:
>> for lines in FileObject:
>> linelist=lines.split('\t')
>> Key=linelist[0]
>> ValCity=(linelist[12]).strip()
>> ValState=linelist[13]
>> ValOne=linelist[2]
>> ValTwo=linelist[6]
>> ValThree=boolean(linelist[7])
>> D={Key:(ValOne, ValTwo, ValThree, ValCity,ValState)}
>
> Put the line above inside the for loop :)
>
Won't help. Then he'd be reassigning the D each time, with the same net
result. What he needs INSIDE the loop is something like:
D[Key] = (ValOne, ValTwo, ValThree, ValCity, ValState)
>> return D
>> print fieldict("DOT500.txt")
>>
>
--
DaveA
More information about the Tutor
mailing list