I'm trying to zip two lists with the same length, but I always get the error "zip object at 0x0000000002A81548" instead of a zipped list.
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))
movielist= list(zip(moviename,moviedate))
In Python 2 zip
returns a list and the above is not needed. In Python 3 it returns a special lazy zip object, similar to a generator or itertools.izip
, which you need to make concrete to use len
. The same is true for map
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.