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

后端 未结 9 2010
北荒
北荒 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 14:01

    >>> flat_list = []
    >>> nested_list = [(1, 2, 4), (0, 9)]
    >>> for a_tuple in nested_list:
    ...     flat_list.extend(list(a_tuple))
    ... 
    >>> flat_list
    [1, 2, 4, 0, 9]
    >>> 
    

    you could easily move from list of tuple to single list as shown above.

提交回复
热议问题