Python3: zip in range
Question: I'm new to Python and I'm trying to zip 2 lists together into 1, which I was
already able to do. I've got 2 lists with several things in them, but I'm
asking the user to input a number, which should determine the range. So i've
got List1: A1, A2, A3, A4, A5, A6 and List2: B1,B2,B3,B4,B5,B6 I know how to
display the 2 complete lists, but what I'm trying to do is, if the user enters
number "3", the zip should only display: (A1,B1), (A2,B2), (A3,B3) instead of
the whole list. So here's what I tried:

    
    
    a = ["A1", "A2", "A3", "A4", "A5", "A6"]
    b = ["B1", "B2", "B3", "B4", "B5", "B6"]
    c = zip(a,b)
    number = int(input("please enter number"))
    for x in c:
        print(x[:number])
    

But this doesn't work. I tried to look it up, but couldn't find anything. I
would be glad, if someone could help me out.


Answer: You can slice the result of `zip()` with
[`itertools.islice()`](https://docs.python.org/3/library/itertools.html#itertools.islice):

    
    
    >>> from itertools import islice
    >>> list(islice(c, number))
    [('A1', 'B1'), ('A2', 'B2'), ('A3', 'B3')]
    

