question about a program

Andreas Waldenburger usenot at geekmail.INVALID
Fri Oct 8 21:49:01 CEST 2010


On Thu, 7 Oct 2010 17:39:51 -0700 (PDT) Logan Butler
<killable1337 at gmail.com> wrote:

> question about an assignment:
> 
> >>> places("home sweet home is here",' ')
> [4, 10, 15, 18]
> 
> this is my code:
> 
> def places(x, y):
>     return [x.index(y) for v in x if (v == y)]
> 
> so far I'm only getting
> [4, 4, 4, 4]
> 
> so the first value is correct, it is just not iterating on to the next
> three items it needs to

<http://docs.python.org/tutorial/datastructures.html>

list.index(x)
    Return the index in the list of the first item whose value is x. It
    is an error if there is no such item.

/W

-- 
To reach me via email, replace INVALID with the country code of my home 
country.  But if you spam me, I'll be one sour Kraut.




More information about the Python-list mailing list