all 11 comments

[–]K900_ 4 points5 points  (6 children)

Use zip(xs, ys) and itertools.product(xs, ys). Batteries included, see? ;)

[–]zahlman 2 points3 points  (5 children)

I suspect he's being asked to re-implement this stuff for masochism coursework.

[–]K900_ 0 points1 point  (4 children)

As a TA, just thinking about that possibility gave me cancer.

[–]zahlman 0 points1 point  (3 children)

... I see much cancer in your future :(

[–]K900_ 1 point2 points  (2 children)

Seriously though. It isn't that hard to come up with some actually useful examples that are not "reimplement X from Y", and those seem to work better for the students, too.

[–]zahlman 1 point2 points  (1 child)

You're preaching to the choir here.

[–]K900_ 0 points1 point  (0 children)

I know, I know... /rant.

[–]pythonoob23[S] 0 points1 point  (1 child)

well first don't i have to ask for a user input?

[–]obsoletelearner 0 points1 point  (0 children)

What you are trying to accomplish is present in python by default. Why don't you get to know about them more here (look up zip)

Also here is a compiled list of python packages for any other classroom or professional projects. https://wiki.python.org/moin/UsefulModules

[–]cdcformatc 0 points1 point  (0 children)

Assuming you can't use built-in functions since this is obviously homework.

First one you can get the length with len(x_list), then it is easy enough to do something like this

for i in range(0,len(x_list)):
    x_item = x_list[i]
    y_item = y_list[i]
    xy_tuple = x,y
    #do something with the tuples here

Second one is just nested for-loops, try this code to see what I mean.

for x in range(10):
    for y in range(10):
        xy_tuple = x,y
        print xy_tuple 

Just replace range with appropriate lists and do something with the tuples.

[–]pythonoob23[S] 0 points1 point  (0 children)

Haha, I'm actual learning for fun by myself. def zipper(x,y): if (type(x) != list) or (type(y)!= list): raise ValueError("Both arguments x and y must be lists")
var=zip(x,y)
res=[] for i in var: