Re: [Tutor] Using type

2011-08-12 Thread Emeka
Chris, I was just fooling around and I wanted to do something for myself before going to bed the other night. func myflatten will turn say [ 34 [90] [12] 1] into [34 90 12 1]. Just like its name sounds. Emeka On Fri, Aug 12, 2011 at 7:03 PM, Christopher King wrote: > try: >> it

Re: [Tutor] Using type

2011-08-12 Thread Christopher King
> > try: > iter(item) # test for iterability > if len(item) == 1 and item == item[0]: > gut.append(item) > else: > gut = gut + flatten(item) > > except TypeError: > gut.append(item) > I wouldn't put the what you want to do i

Re: [Tutor] Using type

2011-08-12 Thread Dave Angel
On 08/12/2011 05:31 AM, ALAN GAULD wrote: It'll work on lists and tuples, for simple examples. But beware that when you iterate through strings, the individual characters are also strings, and this function will fail with an error like: RuntimeError: maximum recursion depth exceeded Oh,

Re: [Tutor] Using type

2011-08-12 Thread ALAN GAULD
> It'll work on lists and tuples, for simple examples. But beware that > when you iterate through strings, the individual characters are also > strings, and this function will fail with an error like: >RuntimeError: maximum recursion depth exceeded Oh, good catch Dave. So you'd want to a

Re: [Tutor] Using type

2011-08-12 Thread Dave Angel
On 08/12/2011 03:47 AM, Alan Gauld wrote: On 12/08/11 07:04, Emeka wrote: Hello All, I need help here, type(item) == [].__class__:. What is the idiomatic way of doing it? if type(item) == type([])... or in this case if type(item) == list... But probably preferrable to using type is to use

Re: [Tutor] Using type

2011-08-12 Thread Alan Gauld
On 12/08/11 07:04, Emeka wrote: Hello All, I need help here, type(item) == [].__class__:. What is the idiomatic way of doing it? if type(item) == type([])... or in this case if type(item) == list... But probably preferrable to using type is to use isinstance: if isinstance(item, list)...

[Tutor] Using type

2011-08-11 Thread Emeka
Hello All, I need help here, type(item) == [].__class__:. What is the idiomatic way of doing it? def myflatten(my_data): gut = [] for item in my_data: if type(item) == [].__class__: gut = gut + myflatten ( item) else: gut.append(item) return gut print myfl