Transform “list of tuples” into a flat list or a matrix

后端 未结 9 2016
北荒
北荒 2020-11-27 13:17

With Sqlite, a \"select..from\" command returns the results \"output\", which prints (in python):

>>print output
[(12.2817, 12.2817), (0, 0), (8.52, 8.         


        
9条回答
  •  天命终不由人
    2020-11-27 13:58

    In Python 3 you can use the * syntax to flatten a list of iterables:

    >>> t = [ (1,2), (3,4), (5,6) ]
    >>> t
    [(1, 2), (3, 4), (5, 6)]
    >>> import itertools
    >>> list(itertools.chain(*t))
    [1, 2, 3, 4, 5, 6]
    >>> 
    

提交回复
热议问题