coolair
V2EX  ›  问与答

如何优雅的对一个 Python List 进行重新组合?

  •  
  •   coolair · Jun 10, 2016 · 2163 views
    This topic created in 3828 days ago, the information mentioned may be changed or developed.
    原 List 如下:
    [['a', '1', '2', '3'], ['a', '2', '3', '4'], ['b', '3', '4', '5'], ['b', '4', '5', '6']]
    想要变成如下形式:
    [
    [a, [[1, 2, 3], [2, 3, 4]]],
    [b, [[3, 4, 5], [4, 5, 6]]]
    ]
    怎样做更优雅方便呢?
    6 replies  •  2016-06-11 09:34:37 +08:00
    pimin
    pimin
    Jun 10, 2016 via Android
    1
    感觉做成字典更符合你需求
    coolair
    coolair
    OP
    Jun 10, 2016
    2
    @pimin 字典排序就乱了。
    lll9p
    lll9p
    Jun 10, 2016
    3
    from collections import OrderedDict
    imn1
    imn1
    Jun 10, 2016
    4
    pandas 做这个容易
    thinker3
    thinker3
    Jun 10, 2016
    5
    google python groupby list
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   972 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:16 · PVG 04:16 · LAX 12:16 · JFK 15:16
    ♥ Do have faith in what you're doing.