def get_key(file):
'''(file open for reading) -> tuple of objects
Return a tuple containing an int of the group length and a dictionary of
mapping pairs.
'''
f = open(file, 'r')
dic = f.read().strip().split()
group_length = dic[0]
dic[0] = 'grouplen' + group_length
tup = {}
tup['grouplen'] = group_length
idx = 1
dic2 = dic
del dic2[0]
print(dic2)
for item in dic2:
tup[item[0]] = item[1]
print(tup)
return tup
结果是:{'grouplen': '2', '"': 'w'}
dic 2 是:
['"w', '#a', '$(', '%}', '&+', "'m", '(F', ')_', '*U', '+J', ',b', '-v', '.<', '/R', '0=', '1$', '2p', '3r', '45', '5~', '6y', '7?', '8G', '9/', ':;', ';x', '<W', '=1', '>z', '?"', '@[', 'A3', 'B0', 'CX', 'DE', 'E)', 'FI', 'Gh', 'HA', 'IN', 'JS', 'KZ', 'L\\', 'MP', 'NC', 'OK', 'Pq', 'Qn', 'R2', 'Sd', 'T|', 'U9', 'V-', 'WB', 'XO', 'Yg', 'Z@', '[>', '\\V', ']%', '^`', '_T', '`,', 'aD', 'b#', 'c:', 'dM', 'e^', 'fu', 'ge', 'hQ', 'i7', 'jY', 'kc', 'l*', 'mH', 'nk', 'o4', 'p8', 'ql', 'rf', 's{', 'tt', 'uo', 'v.', 'w6', 'xL', 'y]', 'zi', '{s', '|j', '}&', "~'"]
我希望元组包含所有对dic2
,而不仅仅是前两个