Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Bernard Lebel
Thanks for the examples and references everyone. I should clarify though that I was simply looking for a *built-in* feature rather than a function or a list-comprehension. I know these last two works and I currently use a list comprehension. # Example: >>> flatten( [ 1, 3, 4, ('allo', 'bonjour',

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Pujo Aji
Hi,   Use this:def _flatten(seq,myhasil): for isi in seq: if type(isi) != str: try: _flatten(isi,myhasil) except: myhasil.append(isi) else: myhasil.append(isi) def flatten(seq): '''code to flatten tupple''' hasil = [] _flatten(seq,hasil) return

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Alan G
> I have this list wich is made of tuples. I wish I could "flatten" > this list, that is, to extract each element in the tuples and > build a new flat list with it. Recursion is often used for this, there is an example function in my tutorial topic on recursion (using nested lists rather than

Re: [Tutor] Flattening multi-dimentional list

2005-09-28 Thread Kent Johnson
Bernard Lebel wrote: > Hello, > > I have this list wich is made of tuples. I wish I could "flatten" this > list, that is, to extract each element in the tuples and build a new > flat list with it. Is there any shortcut to do that or do I have to go > through some list comprehension-like procedure?

Re: [Tutor] Flattening multi-dimentional list

2005-09-28 Thread Bernard Lebel
Thanks a lot Danny. Bernard On 9/28/05, Danny Yoo <[EMAIL PROTECTED]> wrote: > > > On Wed, 28 Sep 2005, Bernard Lebel wrote: > > > I have this list wich is made of tuples. I wish I could "flatten" this > > list, that is, to extract each element in the tuples and build a new > > flat list with

Re: [Tutor] Flattening multi-dimentional list

2005-09-28 Thread Danny Yoo
On Wed, 28 Sep 2005, Bernard Lebel wrote: > I have this list wich is made of tuples. I wish I could "flatten" this > list, that is, to extract each element in the tuples and build a new > flat list with it. Is there any shortcut to do that or do I have to go > through some list comprehension-lik

[Tutor] Flattening multi-dimentional list

2005-09-28 Thread Bernard Lebel
Hello, I have this list wich is made of tuples. I wish I could "flatten" this list, that is, to extract each element in the tuples and build a new flat list with it. Is there any shortcut to do that or do I have to go through some list comprehension-like procedure? (I have looked at sets but I ha