May-02-2018, 03:42 PM
(This post was last modified: May-02-2018, 03:42 PM by KaleBosRatjes.)
I'm having problems with my code, i want to compare 2 values from a list. There are 4 groups (a,b,c,d) where the values can end up in. A if both values are above 5, b and c if one of the two is above 5 and d if both are below 5. The problem is that the first value will compare with all the values from list 2. I also tried to get the values in tuples but it didn't work?
I'll post my code below.
lists:
[12.4, 2.7, 5.1] [10.9, 2.3, 3.7]
I tried it with using a nestled for loop but it uses all the values from list 1 in 2.
my code:
[12.4, 10.9, 5.1, 10.9] [2.7, 10.9] [12.4, 2.3, 12.4, 3.7, 5.1, 2.3, 5.1, 3.7] [2.7, 2.3, 2.7, 3.7]
desired output:
[(12.4,10.9)][][(5.1,2.3)][(2.7,3.7)]
I'll post my code below.
lists:
[12.4, 2.7, 5.1] [10.9, 2.3, 3.7]
I tried it with using a nestled for loop but it uses all the values from list 1 in 2.
my code:
for i in p1stb_list_new: for j in p2stb_list_new: if i>=5 and j>=5: a.extend((i,j)) elif i<5 and j>=5: b.extend((i,j)) elif i>=5 and j<5: c.extend((i,j)) elif i<5 and j<5: d.extend((i,j)) print(a,b,c,d)output:
[12.4, 10.9, 5.1, 10.9] [2.7, 10.9] [12.4, 2.3, 12.4, 3.7, 5.1, 2.3, 5.1, 3.7] [2.7, 2.3, 2.7, 3.7]
desired output:
[(12.4,10.9)][][(5.1,2.3)][(2.7,3.7)]