寄存地

In order to be irreplaceable, one must always be different

0%

Python数据处理小技巧

删除列表中的重复的dict

1
[dict(t) for t in set([tuple(d.items()) for d in l])]

dict反转

  1. 列表推导

    1
    return dict([(v,k) for k,v in d.iteritems()])
  2. 内置zip

    1
    dict(zip(map(str, d.values()), d.keys()))

    数据量较大时,可利用itertools提高大数据效率

    1
    2
    3
    from itertools import izip

    dict(izip(d.itervalues(),d.iterkeys()))