Recursive generator for flattening nested lists

前端 未结 5 1561
离开以前
离开以前 2020-12-03 12:04

I\'m a programming newbie and am having some trouble understanding an example from my python textbook (\"Beginning Python\" by Magnus Lie Hetland). The example is for a recu

5条回答
  •  醉话见心
    2020-12-03 12:47

    the try except construction catches the exception for you and yields nested back which is just the argument that was given to flatten().

    So flatten(1) will go wrong in for sublist in nested: and continues with the except part and yields nested which is 1.

提交回复
热议问题