[Tutor] get as a way to operate on first occurrence of an element in a list?

Sean 'Shaleh' Perry shalehperry@comcast.net
Sun Aug 3 03:54:01 EDT 2003


>
> This is a working version in python:
>
>  for line in f:
>      if line in seen_dict:
>          pass
>      else:
>          print line,
>          seen_dict[line] = 1
>

why not use the following?

for line in f:
   if line not in seen_dict:
       print line,
       seen_dict[line] = 1

that seems to say what you mean in a more succinct way.





More information about the Tutor mailing list