Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

i and j equivalent in python

$
0
0

I was wondering what the equivalent of "i" and "j" in C++ is in python. What I am trying to do is add each number in one set to the corresponding one in another (i.e. in the example below: [2+1], [4+3], [6+5]) I am trying to teach myself python off the internet, and I couldn't find how to do this. [example below doesn't work.]

even = [2,4,6]odd = [1,3,5]both = []for i in range even[]:    for j in range odd[]:        if(i==j):            both.append(even[i] + odd[j])print(both)

I tried doing this:

for number1 in even:    for number2 in odd:        if(number1==number2):            both.append(number + number2)

but this only performs addition if the numbers themselves are equal, which is not what I want. Any help would be appreciated. Thanks!


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>