problem with lists

Sean 'Shaleh' Perry shalehperry at attbi.com
Wed Sep 11 18:05:38 EDT 2002


On Wednesday 11 September 2002 14:54, Manuel Hendel wrote:
> for line in lines:
>         line = string.strip(line)[1:-1]
>         fields = string.split(line, "|")
>
>         domains = []
>
>         if not domains.index(fields[3:4]):
>             domains.append(fields[3:4])
>
> print domains
>
> This brings the following error message:
> :!./pop3create.py pop3data
>
> [No write since last change]
> Traceback (most recent call last):
> File "./pop3create.py", line 22, in ?
> if domains.index(fields[3:4]):
> ValueError: list.index(x): x not in list
>
> Can someone explain this to me?
>
> Thanks,
>     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.




More information about the Python-list mailing list