Compare two variable lists in python

I have two lists in python with elements. I want to perform some checks on these two lists. My lists are as follows:

list_A = [["'EASY'", "'LEVEL_C'", "'4'", '0.714', '\n'], ["'EASY'", "'LEVEL_D'", "'5'", '0.778', '\n'], ["'EASY'", "'LEVEL_D'", "'5'", '0.226', '\n'], ["'EASY'", "'LEVEL_D'", "'5'", '0.222', '\n'], ...]
list_B = [["'EASY'", "'LEVEL_B'", "'2'", '1.000', '\n'], ["'EASY'", "'LEVEL_C'", "'3'", '1.000', '\n'], ["'EASY'", "'LEVEL_D'", "'4'", '1.000', '\n'], ["'EASY'", "'LEVEL_D'", "'4'", '0.290', '\n'], ...]

For the variable "EASY" and for the level of the variable that takes values ​​(LEVEL_A - LEVEL_F), there is a third variable corresponding to the estimate (1-6) and the confidence variable (0-1). What I want to do is to compare the two lists for the variable easy and level and find in all cases which of the two lists (list_A and list_B) has the highest score and with certainty. How can i do this?

The way I build my rules, first I got the lines received from the executable file and filtered them in the lists. A prime example for my listings is:

Rule: ('EASY', 'LEVEL_E') ==> ('4') , 0.182 
'EASY' 'LEVEL_E' '4'  0.182 
["'EASY'",  "'LEVEL_E'", , "'4'", '0.182', '\n']

and the code I use to create the vector:

 for row in my_lines:
   print row
   row = re.sub('[()]', "", row)
   row = row.replace("Rule: ", "")
   row = row.replace(",", "")
   row = row.replace("==>", "")
   print row
   split = re.split(r' +', row)
   print split

, , , Level:

list_A.sort(key=lambda x: x[1])
list_B.sort(key=lambda x: x[1])

EDIT: . . , , , , . ?

+4
2

, dict dict:

dict_a = {
    'LEVEL_D': {'difficulty': 'EASY', 'score': 1, 'confidence': 0.778},
    'LEVEL_F': {'difficulty': 'EASY', 'score': 6, 'confidence': 0.750},
    'LEVEL_C': {'difficulty': 'EASY', 'score': 7, 'confidence': 0.714},
    }

dict_b = {
    'LEVEL_F': {'difficulty': 'EASY', 'score': 8, 'confidence': 0.800},
    'LEVEL_B': {'difficulty': 'EASY', 'score': 2, 'confidence': 0.900},
    'LEVEL_D': {'difficulty': 'EASY', 'score': 3, 'confidence': 1.000},
    }

dicts:

for level in dict_a:
    if level in dict_b:
        stats_a = dict_a[level]
        stats_b = dict_b[level]
        score_a = stats_a['score']
        score_b = stats_b['score']
        conf_a = stats_a['confidence']
        conf_b = stats_b['confidence']
        print(level, score_a, score_b, conf_a, conf_b)

, . , . , .

: , :

for level in dict_a:
    if level in dict_b:
        stats_a = dict_a[level]
        stats_b = dict_b[level]
        container = 'A' if stats_a['score'] > stats_b['score'] else 'B'
        print('Container {} has the higher score for level {}.'.format(container, level))
+2

, , , , . :

list_A.sort(key=lambda x: x[1])
list_B.sort(key=lambda x: x[1])
res = zip(list_A, list_B)

, , .

+1

Source: https://habr.com/ru/post/1674726/


All Articles