python list comprehensions; compressing a list of lists?

后端 未结 13 1958
名媛妹妹
名媛妹妹 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:04

    You can find a good answer in itertools' recipes:

    def flatten(listOfLists):
        return list(chain.from_iterable(listOfLists))
    

    (Note: requires Python 2.6+)

提交回复
热议问题