Re: [BangPypers] Python List Comprehension Question

2014-10-03 Thread Bhargav Kowshik
Thank you Kracekumar. http://docs.python-guide.org/en/latest/writing/gotchas/#what-you-wrote"Python’s default arguments are evaluated once when the function is defined,not each time the function is called." Thank you, Bhargav. On Friday, October 3, 2014 9:18 PM, kracekumar ramaraju wro

Re: [BangPypers] Python List Comprehension Question

2014-10-03 Thread kracekumar ramaraju
On Fri, Oct 3, 2014 at 9:04 PM, Bhargav Kowshik < bhargav.kows...@yahoo.com.dmarc.invalid> wrote: > Nice! Thank you very much Anand.But, I still don't know what is > happening.Please point me to a resource to understand what is happening. > > A common beginner mistake. More of such gotcha can be f

Re: [BangPypers] Python List Comprehension Question

2014-10-03 Thread Bhargav Kowshik
Nice! Thank you very much Anand.But, I still don't know what is happening.Please point me to a resource to understand what is happening. ** Program ** def flat_it(values, result=list()):     for v in values:     if isinstance(v, list):     flat_it(v, result)     else:    

Re: [BangPypers] Python List Comprehension Question

2014-10-03 Thread Anand Chitipothu
On Fri, Oct 3, 2014 at 8:26 PM, Bhargav Kowshik < bhargav.kows...@yahoo.com.dmarc.invalid> wrote: > We could use what Anand talked about at Pycon India about handling the > headers in first row of a CSV.In this scenario, instead of default for > result being None and checking if None everytime, we

Re: [BangPypers] Python List Comprehension Question

2014-10-03 Thread Bhargav Kowshik
We could use what Anand talked about at Pycon India about handling the headers in first row of a CSV.In this scenario, instead of default for result being None and checking if None everytime, we could have the default value an empty list. def flat_it(values, result=list()):     for v in values:

[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

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

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
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 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

[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