4

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))
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Linhzy Pham
  • 53
  • 1
  • 4
  • 3
    Sounds like a duplicate of http://stackoverflow.com/questions/31011631/python-2-3-object-of-type-zip-has-no-len or http://stackoverflow.com/questions/18048310/len-error-for-zipping-in-python. – alecxe May 02 '16 at 02:20

1 Answers1

7
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.

Alex Hall
  • 34,833
  • 5
  • 57
  • 89