python list comprehensions; compressing a list of lists?

后端 未结 13 1989
名媛妹妹
名媛妹妹 2020-11-30 01:49

guys. I\'m trying to find the most elegant solution to a problem and wondered if python has anything built-in for what I\'m trying to do.

What I\'m doing is this. I

13条回答
  •  我在风中等你
    2020-11-30 02:09

    Google brought me next solution:

    def flatten(l):
       if isinstance(l,list):
          return sum(map(flatten,l))
       else:
          return l
    

提交回复
热议问题