[Tutor] problem with circular list

Tim Condit tcondit@gblx.net
Mon, 23 Jul 2001 07:59:46 -0700


On Sun, Jul 22, 2001 at 12:10:43PM -0700, Danny Yoo wrote:
> On Sun, 22 Jul 2001, Tim Condit wrote:
> 
> > I found this problem and thought it would be fun, but it's got me
> > stumped.  The full text is at
> > http://www.karrels.org/Ed/ACM/weur94p/prob_b.html .  To sum it up, there
> > is a king, an executioner, and a variable number of condemned prisoners.
> 
> Ah, the Josephus problem!
> 
[snip]

> Side note: you can avoid depending on IndexError altogether by using the
> "modulo" operator '%'.  The modulo operator is traditionally used for
> things that "wrap around":
> 
> ###
> >>> for i in range(10):
> ...     print i % 3
> ...
> 0
> 1
> 2
> 0
> 1
> 2
> 0
> 1
> 2
> 0
> ###
> 

I used this originally, then dropped it in favor of subtraction.. seemed
like a good idea at the time. 

[snip]
> 
> You don't want to use remove(): it removes items from a list based on
> an element's value, not position:
> 
> 
> ###
> Help on built-in function remove:
>  
> remove(...)
>     L.remove(value) -- remove first occurrence of value
> ###
> 
> 
> What you'll want to use, instead, is the deleting operator, 'del':
> 
> ###
> >>> mylist = range(10)
> >>> del mylist[0]
> >>> mylist
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
> >>> del mylist[1]
> >>> mylist
> [1, 3, 4, 5, 6, 7, 8, 9]
> ###
> 
> del would be a more appropriate way to... execute the deletion.
> 

Ah!  That's exactly what I wanted, and it's right under my nose.  Time
for a refresher of the basics.

Thanks for the help, 
Tim


--- end quoted text ---

-- 
Tim Condit                        Detroit NCC
800-414-5028                      Global Crossing

The plan was simple.  Unfortunately, so was Bullwinkle.