编程语言
首页 > 编程语言> > python中求列表的并集差集

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)))

  

标签:中求,python,list,get,kline,currency30m,currency,集差集,time
来源: https://www.cnblogs.com/zhaooyw/p/16029107.html