python中求列表的并集差集

  •   以上代码是求两个列表的并集
    # 获取不同的列表集
def get_order_currency(kline_time ):
      if kline_time=='15m':
     
        return [1, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9]
      else:
        return  [ 4, 5, 6, 6, 6, 7, 8, 9]


    kline_time = '15m'
    list_currency15m = get_order_currency()

    kline_time = '30m'
    list_currency30m = get_order_currency()

    # 求15分钟和30分钟两个集合的并集
    ret2 = list(set(list_currency15m).union(set(list_currency30m))) 
# 求两个列表的差集
ret2 = [ i for i in list_currency15m if i not in list_currency30m ]
kline_time = '15m' list_currency15m = get_order_currency()
    kline_time = '30m'    list_currency30m = get_order_currency()
    # 求15分钟和30分钟两个集合的并集   
    ret2 = list(set(list_currency15m).union(set(list_currency30m)))

  

posted @ 2022-03-20 10:20  zhenzhen78  阅读(201)  评论(0编辑  收藏  举报