【问题标题】:How compare 12 List's如何比较 12 个列表
【发布时间】:2017-06-21 16:07:38
【问题描述】:

所以,我有 12 个带有 Number 的列表,我会将它与带有 Number 的 Input 进行比较。我会让每个 List 与输入进行比较,并打印与输入相似的数字。

示例:

输入:2 14 34 12 23 45

第一个列表:[“2”,“14”,“18”,“28”,“40”,“48”]

输出 2 14

我的代码:

w = raw_input("give number: ").split()


a1 = ["2", "14", "18", "28","40", "48"]
a2 = ["5", "9", "17", "21", "32", "49"]
a3 = ["4", "18", "19", "30", "47", "49"]
a4 = ["9", "15", "25", "28", "39", "43"]
a5 = ["8", "11", "13", "25", "39", "48"]
a6 = ["3", "12", "13", "14", "31", "33"]
a7 = ["3", "12", "14", "23", "26", "45"]
a8 = ["1", "10", "12", "15", "18", "37"]
a9 = ["6", "7", "17", "38", "41", "44"]
a10 = ["1", "7", "14", "17", "27", "35"]
a11 = ["15", "23", "25", "26", "39", "48"]
a12 = ["5", "12", "14", "30", "41", "48"]

for a,b,c,d,e,f,g,h,i,j,k,l in zip(a1, b2, c3, d4, e5, f6, g7, h8, i9, j10, k11, l12):
  if a in w :
     print "(1)", a
  elif b in w:
     print "(2)", b
  elif c in w:
     print "(3)", c
  elif d in w:
     print "(4)", d
  elif e in w:
     print "(5)", e
  elif f in w:
     print "(6)", f
  elif g in w:
     print "(7)", g
  elif h in w:
     print "(8)", h
  elif i in w:
     print "(9)", i
  elif j in w:
     print "(10)", j
  elif k in w:
     print "(11)", k
  else:
     print "(12)", a

这就是我来的......

给号码:2 14 18 28

(1) 2

(1) 14

(1) 18

(1) 28

(8) 40

(12) 48

你能帮帮我吗....谢谢!

【问题讨论】:

    标签: python-2.7 list compare


    【解决方案1】:

    人们帮助我解决这个问题(不是在这里......)......非常感谢他们!!,我的问题的解决方案......我写的解决方案也许其他人需要它......

    bet_numbers = [
        {"2", "14", "18", "28","40", "48"},
        {"5", "9", "17", "21", "32", "49"},
        {"4", "18", "19", "30", "47", "49"},
        {"9", "15", "25", "28", "39", "43"},
        {"8", "11", "13", "25", "39", "48"}, #created set Lists with curly braces {}
        {"3", "12", "13", "14", "31", "33"},
        {"3", "12", "14", "23", "26", "46"},
        {"1", "10", "12", "15", "18", "37"},
        {"6", "7", "17", "38", "41", "44"},
        {"1", "7", "14", "17", "27", "35"},
        {"15", "23", "25", "26", "39", "48"},
        {"5", "12", "14", "30", "41", "48"},
    ]
    
    drawn_numbers = set(raw_input("drawn numbers: ").split()) # build a set List
    
    for index, numbers in enumerate(bet_numbers, start=1): #with enumerate(),enumerate each List 
       correct = drawn_numbers & numbers  #with "identifier" add Input + numbers = (1), (2),....
       if correct:  #if statement without comparison because True is...
          print "({}) {}".format(index, ', '.join(sorted(correct)))
    
          #"({}) {}".format() = concatenate elements together .
          # (index, ', '.join(sorted(correct))) = (1), (2),...sorted(correct),sorted the set lists output  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多