[Tutor] Re: mixed tuples and lists to nested lists

kevin parks kp87@lycos.com
Fri, 20 Jul 2001 06:39:29 +0900


The following works fine, except it only goes one level deep. Hmmm... If i only understood recursion.... i have a feeling that's the next step.....

I had no idea that you could just do:
list(i), since tuples are supposed to be immutable i somehow expected that changing the type would be harder. All the books make such a big deal about how you have to be wearing special color socks and the moon as to be in the right phase. Bravo to Mr. Chun for unmasking tuples for what the really are: sort of immutable. imposters!

def foo(seq):
	if type(seq)!=type([]):
		return 0
	out=[]
	for i in seq:
		out.append(list(i))
	return out

---

On Fri, 20 Jul 2001 05:27:01  
 kevin parks wrote:
>Here is a problem i come up against frequently and i guess i should know this by
>now, but i don't. Some times if you fiddle around with things you end up with a list
>whose list elements contain not only lists, but nested lists, and *gasp* 
>those Beckett-esque immutable tuples.
>
>An example might be:
>
>[(1, 100, 'w'), (2, 101, 'x'), (3, 102, 'y'), (4, 103, 'z')]
>
>how do i change that to be:
>
>[[1, 100, 'w'], [2, 101, 'x'], [3, 102, 'y'], [4, 103, 'z']]
>
>A pathalogical example would be to turn something like
>this in to a list of lists:
>
>['abc',[(1,2), ([3],4)],5]
>
>cheers,
>
>back to the interpreter
>
>kevin
>



Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/