Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 如何比较12个列表';s_Python 2.7_List_Compare - Fatal编程技术网

Python 2.7 如何比较12个列表';s

Python 2.7 如何比较12个列表';s,python-2.7,list,compare,Python 2.7,List,Compare,所以,我有12个带数字的列表,我会将其与一个带数字的输入进行比较。我会将每个列表与输入进行比较,并打印与输入相似的数字 例如: 输入:2143412345 第一个清单:[“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"] a

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

例如:

输入:2143412345

第一个清单:[“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
这就是我要来的

提供号码:2141828

(1) 二,

(1) 十四,

(1) 十八

(1) 二十八

(8) 四十

(12) 四十八


你能帮帮我吗。。。。谢谢

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

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