[BangPypers] Python List Comprehension Question

2014-10-02 Thread Rajiv Subramanian M
Hello Group, I'm Rajiv working as web developer in bangalore. Objective: We need to convert the list containing integers and nested list of integer in it e.g.) x = [[1, 2, [3]], 4] into a flat list format e.g.) result = [1, 2, 3, 4] MyAnswer using Recursive function: def flat_it(List): resul

Re: [BangPypers] Python List Comprehension Question

2014-10-02 Thread Anand Chitipothu
On Thu, Oct 2, 2014 at 3:51 PM, Rajiv Subramanian M wrote: > Hello Group, > > I'm Rajiv working as web developer in bangalore. > > Objective: > We need to convert the list containing integers and nested list of integer > in it > e.g.) x = [[1, 2, [3]], 4] > into a flat list format > e.g.) result

Re: [BangPypers] Python List Comprehension Question

2014-10-02 Thread kracekumar ramaraju
Hi `yield from ` is introduced in Python 3.3 as part of pep 380. # python 3.3 from collections import Iterable def flatten(items): for item in items: if isinstance(item, Iterable): yield from flatten(item) else: yield item list(flatten([[1, 2, [3]],

Re: [BangPypers] Python List Comprehension Question

2014-10-02 Thread Abhishek L
On Thu, Oct 2, 2014 at 5:15 PM, kracekumar ramaraju wrote: > Hi > > `yield from ` is introduced in Python 3.3 as part of pep 380. > > # python 3.3 > > from collections import Iterable > > def flatten(items): > for item in items: > if isinstance(item, Iterable): > yield from

Re: [BangPypers] Python List Comprehension Question

2014-10-02 Thread kracekumar ramaraju
On Thu, Oct 2, 2014 at 6:34 PM, Abhishek L wrote: > On Thu, Oct 2, 2014 at 5:15 PM, kracekumar ramaraju > wrote: > > Hi > > > > `yield from ` is introduced in Python 3.3 as part of pep 380. > > > > # python 3.3 > > > > from collections import Iterable > > > > def flatten(items): > > for item

[BangPypers] Python List Comprehension Question

2014-10-02 Thread Rajiv Subramanian M
Hi Krace, I believe as your code returns a generator instance it must be efficient in handling large input as well. And as you said in previous reply I've added "not isinstance(item, (str, bytes))", the code looks like def flat_it(items): for item in items: if isinstance(item, Iterabl