problem with lists
Greg Fortune
lists at gregfortune.com
Thu Sep 12 15:38:14 EDT 2002
Uwe Schmitt wrote:
> Sean 'Shaleh' Perry <shalehperry at attbi.com> wrote:
>>> Manuel
>
>> You want to use :
>
>> if fields[3:4] not in domains:
>> domains.append(fields[3:4])
>
>> .index() only works if the item is actually in the list.
>
> At least you should wrap the line with .index in a try/except pair...
> But the solution with "in" is preferable.
>
> Greetings, Uwe
>
>
Or simply use .count instead of a try/except block.
if(domains.count(fields[3:4]) == 0)
will work exactly like 'not in'. In this case, I would prefer the 'not in'
option, but wrapping a .index in a try/except seems like a huge overkill.
IMHO, avoid exceptions if possible.
Greg Fortune
Fortune Solutions
More information about the Python-list
mailing list