Re: iterating over a list as if it were a circular list

2013-03-08 Thread Steven D'Aprano
On Thu, 07 Mar 2013 09:27:42 +, Sven wrote: > Additionally, what if I wanted to pull a random element from N, but I > want to ensure all elements from N have been used before starting to > pick already chosen random elements again. So far I thought of > duplicating the list and removing the ra

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 08.03.2013 00:49, schrieb Alexander Blinne: > http://docs.python.org/3/library/itertools.html#itertools.repeat obviously I was aiming for http://docs.python.org/2/library/itertools.html#itertools.cycle here Greetings -- http://mail.python.org/mailman/listinfo/python-list

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Alexander Blinne
Am 07.03.2013 10:27, schrieb Sven: > Now I would like to iterate over P and place one N at each point. > However if you run out of N I'd like to restart from N[0] and carry on > until all the points have been populated. > So far I've got (pseudo code) > > i = 0 > for point in points: > put N[i

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Roy Smith
In article , Sven wrote: > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can > always assume that > > len(N) <= len(P) > > Now I would like to iterate over P and place one N at each point. However

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Rebert
On Mar 7, 2013 1:29 AM, "Sven" wrote: > > Stupid keyboard shortcuts, sent it too early. Apologies > > > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can always assume that > > len(N) <= len(P) > > Now

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Sven
On 7 March 2013 09:31, Chris Rebert wrote: > On Mar 7, 2013 1:24 AM, "Sven" wrote: > > > > I was wondering what the best approach for the following might be. > > > > Say you have a list P of points and another list N of other items. You > can always assume that > > > > len(N) <= len(P) > > > > N

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Rebert
On Mar 7, 2013 1:24 AM, "Sven" wrote: > > I was wondering what the best approach for the following might be. > > Say you have a list P of points and another list N of other items. You can always assume that > > len(N) <= len(P) > > Now I would like to iterate over P and place one N at each point.

iterating over a list as if it were a circular list

2013-03-07 Thread Sven
Stupid keyboard shortcuts, sent it too early. Apologies I was wondering what the best approach for the following might be. Say you have a list P of points and another list N of other items. You can always assume that len(N) <= len(P) Now I would like to iterate over P and place one N at each p

Re: iterating over a list as if it were a circular list

2013-03-07 Thread Chris Angelico
On Thu, Mar 7, 2013 at 8:23 PM, Sven wrote: > Now I would like to iterate over P and place one N at each point. However if > you run out of N I'd like to restart from N[0] and carry on until all the > points have been populated. Check out itertools.cycle, it should do what you want. ChrisA -- h

iterating over a list as if it were a circular list

2013-03-07 Thread Sven
I was wondering what the best approach for the following might be. Say you have a list P of points and another list N of other items. You can always assume that len(N) <= len(P) Now I would like to iterate over P and place one N at each point. However if you run out of N I'd like to restart from