我试图压缩两个长度相同的列表,但我总是得到错误 " zip对象位于0x0000000002A81548"而不是压缩列表。
filename = input("Which file do you want to open?: \n")
file = open("C:/"+ filename,'r')
movielist = []
moviename = []
moviedate = []
for line in file:
line.strip()
name = re.search('name:(.*)',line)
date = re.search('date:(.*)',line)
if name:
titel = name.group(1)
moviename.append(titel)
if date:
datum = date.group(1)
moviedate.append(datum)
print("Name of the list: ", moviename.pop(0))
movielist= zip(moviename,moviedate)
print(movielist)
print("Number of movies: " , len(moviename))
答案 0 :(得分:4)
movielist= list(zip(moviename,moviedate))
在Python 2 zip
中返回一个列表,不需要上面的内容。在Python 3中,它返回一个特殊的惰性zip对象,类似于生成器或itertools.izip
,您需要具体使用len
。 map
也是如此。