Python: Uniqueness for list of lists

后端 未结 6 1025
慢半拍i
慢半拍i 2020-11-29 00:37

I am curious what would be an efficient way of uniquefying such data objects:

testdata =[ [\'9034968\', \'ETH\'], [\'14160113\', \'ETH\'], [\'9034968\', \'ETH         


        
6条回答
  •  抹茶落季
    2020-11-29 00:52

    Use unique in numpy to solve this:

    import numpy as np
    
    np.unique(np.array(testdata), axis=0)
    

    Note that the axis keyword needs to be specified otherwise the list is first flattened.

    Alternatively, use vstack:

    np.vstack({tuple(row) for row in testdata})
    

提交回复
热议问题