I have two lists: ra_list, e_list.
ra_list is a list of random numbers, e_list is a list with tuples consisting on a number and a categorisation.
A number from ra_list is compared to the number in e_list, and its category is given, as follows:
ra_list = [5,5,6,7,7]
e_list = [(7, A), (7, B), (6, C), (5,D)]
for x in ra_list:
val = None
for i in xrange(0,len(e_list)-1):
if x[1] >= e_list[i][1] and x[1] < e_list[i+1][1]:
val = e_list[i][0]
if val == None:
val = e_list[-1][0]
print x, val
The current output looks like: 5 D, 5 D, 6 C, 7 B, 7 B
This runs partially fine, however when I have two numbers within two tuples with diferente categorisations only one is considered and selected as result (e.g. the program states that a 7 from ra_list is always B, but, as you can see, A is also 7)
Is it possible to implement a list within a list that will randomise between A and B? Or if there was another categorisation with the same number, e.g. if A and B were 7 and C and D were 6, it'd randomly pick A or B and C or D. I know that I can randomise through a list with:
random.choice(list_of_duplicates)
But I'm struggling on how to create the list of duplicates and join it with the original list.
If anyone has a suggestion or can point me in the right direction I'd appreciate it. Thank you!
EDIT
What it ra_list are floats, and thus in the range between element 1 and element 2? e.g.
ra_list = [7.53, 3.42, 35.64]
e_lst = [(a, 7), (b, 7), (c,8), (d,23)]
Output would be 7.53 a or b as its in the range between a,b and c.