-1
def flatten(nstd_list):
    for item in nstd_list:
        try:
            yield from flatten(item)
        except TypeError:
            yield item

I am a beginner for python, can you here please explain me how does this work(step by step)

Andy
  • 49,085
  • 60
  • 166
  • 233
MALLINATH
  • 1
  • 1
  • Have you ever tried about reading python documentation? Once you read it, ask what you don understand. – Axxiss Apr 05 '16 at 13:33
  • hi thank you for your reply,I have gone through the documentation, I am struck at the word ""yield'" here, – MALLINATH Apr 05 '16 at 13:44
  • http://stackoverflow.com/questions/231767/what-does-the-yield-keyword-do-in-python – Axxiss Apr 05 '16 at 13:47

1 Answers1

0

you can take yield as return, so the code is to get every single element from a nested list.

for example:

nstd_list = [[1],2]

first round: item is [1] and 2, so yield flatten([1]) and 2

second round: item is 1, and return 1

co2y
  • 179
  • 12