Answer the question
In order to leave comments, you need to log in
How to loop through tuples?
Good afternoon!
In responses to SQL queries, I receive a tuple in the 1st response and tuples in the second.
For example (10, 20, 30)
and [(5, 10, 15), (11, 12, 14)]
(may not be 2, 122 sets in the second answer) respectively.
I can't figure out how to make a loop to divide the response values (of the first tuple) into the corresponding values of the second response.
Here in this form - everything works, but it's a little (absolutely) not that.
a = (10, 20, 30)
w = (5, 10, 15)
ee = zip(a,w)
for a,w in ee:
print(a*w)
c.execute('SELECT sid, kol, bot FROM stocks')
c2.execute('SELECT sid, kol, bot FROM stul')
Answer the question
In order to leave comments, you need to log in
a = (10, 20, 30)
b = [(5, 10, 15), (11, 12, 14)]
c = list()
for i, v in enumerate(b):
c.insert(i, [])
for x, y in zip(a, v):
c[i].append(x * y)
print(c)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question