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