[Tutor] how to unique the string

lina lina.lastname at gmail.com
Mon Oct 24 10:04:04 CEST 2011


<snip>
>>
>> def translate_process(dictionary,tobetranslatedfile):
>>     results=[]
>>     unique={}
>>     for line in open(tobetranslatedfile,"r"):
>>         tobetranslatedparts=line.strip().split()
>>         results.append(dictionary[tobetranslatedparts[2]])
>>         unique=Counter(results)
>>         with open(base+OUTPUTFILEEXT,"w") as f:
>
> Every time you do this, you're truncating the file.  It'd be better to open
> the file outside the for-line loop, and just use the file object in the
> loop.

 Before I did not understand well, until I read Peter's following post.

Thanks,
<snip>
>
> --
>
> DaveA
>
>


More information about the Tutor mailing list