0
Good afternoon!
I have the list:
a=[4,3, 1, 2, 3]
and the list:
sub_ind_novo=[96, 7, 97, 23, 18]
And I needed to link the lists by getting the result:
no97. G1 #when sub_ind_novo is 97, the corresponding in a is 1, so just print this 1 time
I need the sub_ind_new element printed as the number of times of the corresponding element in a.
(from here, when it takes values other than 1 in a I don’t know how to do.. that is, the 1st element in a is 4, and the respective sub_ind_new is 96, so it should appear 4 lines of this value in the way I write here below in the output example)
The rest should be in this form (example of result):
no23. G1
no23. G2
no7. G1
no7. G2
no7. G3
no18. G1
no18. G2
no18. G3
no96. G1
no96. G2
no96. G3
no96. G4
And I made the following code but I can’t make it for the times when it’s different from 1, that is, where the (2, 3, 4 or 5)..
for i in range(0,len(a)):
if a[i]==1:
print ("no%d. G1 \n" %sub_ind_novo[i])
elif:
.....
print ("no%d. G%d \n" %(sub_ind_novo[i],))
Thank you!
What language is this that Voce speaks?
– user45474
Voce could make a simpler analogy of your problem?
– user45474
I’m working on python 2.7
– Sofia Raimundo
You need to explain better. You want to know what the values of
awhich are equal to 1, and go to the respective index where you found them insub_ind_novo? In this case he submitted he wants to withdraw the figuressub_ind_novo[11]andsub_ind_novo[7]?– Miguel
I’ve already edited, I’ve shortened the list size to make it easier. No, the "a" list is like a list of occurrences of the respective values of "sub_ind_new", so you should print the "sub_ind_new" element the number of times the respective element in "a", as in the result example. (96 has to appear 4 times, in the form: G1, G2, G3, G4; the 23 twice in the form: G1, G2, etc.. )
– Sofia Raimundo
very confusing, puts a larger part of the code and tries to explain better your problem
– Joannis
I’ve already worked it out, thank you!
– Sofia Raimundo