zoukankan      html  css  js  c++  java
  • 将元素为多个列表的列表元素进行转置、去重处理

    >>> a
    [['0068', '20160823', '571', '698038', 0, 0, 0, 0, 0, 0, 0], ['0068', '20160823', '571', '698039', 0, 0, 0, 0, 0, 0, 0], ['0068', '20160823', '571', '698040', 0, 0, 0, 0, 0, 0, 0], ['0068', '20160823', '571', '698041', 0, 0, 0, 0, 0, 0, 0], ['0068', '20160823', '571', '698042', 0, 0, 0, 0, 0, 0, 0], ['0068', '20160823', '571', '698043', 0, 0, 0, 0, 0, 0, 0]]
    >>> len(a)
    6>>> zip(*a)
    [('0068', '0068', '0068', '0068', '0068', '0068'), ('20160823', '20160823', '20160823', '20160823', '20160823', '20160823'), ('571', '571', '571', '571', '571', '571'), ('698038', '698039', '698040', '698041', '698042', '698043'), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 0)]
    >>> set(zip(*a))
    set([(0, 0, 0, 0, 0, 0), ('0068', '0068', '0068', '0068', '0068', '0068'), ('20160823', '20160823', '20160823', '20160823', '20160823', '20160823'), ('571', '571', '571', '571', '571', '571'), ('698038', '698039', '698040', '698041', '698042', '698043')])
    >>> m=map(set,zip(*a))
    >>> m
    [set(['0068']), set(['20160823']), set(['571']), set(['698038', '698039', '698043', '698042', '698041', '698040']), set([0]), set([0]), set([0]), set([0]), set([0]), set([0]), set([0])]
    >>> map(list,m)
    [['0068'], ['20160823'], ['571'], ['698038', '698039', '698043', '698042', '698041', '698040'], [0], [0], [0], [0], [0], [0], [0]]
    >>> len(map(list,m))
    11
    >>> ii= map(list,m)
    >>> ii
    [['0068'], ['20160823'], ['571'], ['698038', '698039', '698043', '698042', '698041', '698040'], [0], [0], [0], [0], [0], [0], [0]]
    >>> ii.count([0])
    7
    >>> 
  • 相关阅读:
    Fence Repair(POJ 3253)
    Saruman's Army(POJ 3069)
    Best Cow Line(POJ 3617)
    一往直前!贪心法
    最基础的“穷竭搜索”
    Lake Counting(POJ 2386)
    Ants(POJ 1852)
    热身题
    分布式锁的三种实现方式
    Redis在实际开发中面临的问题
  • 原文地址:https://www.cnblogs.com/apple2016/p/5804302.html
Copyright © 2011-2022 走看看