Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
list_a = ['United States:PG', 'United States:TV-PG']
list_b = ['PG-13', 'pg-13', 'TV-Y', 'PG', 'pg', 'R', 'r', 'TV-PG', 'tv-pg']

print('list_a before replace_list', list_a, '\n')

def replace_list(list_a, list_b):
#    [string for string in list_a if any(str in string for string in list_b (string.replace(string, str)))]
    new_list = []
    for rating in list_a:
      for short_rating in list_b:
        if short_rating in rating:
          new_list.append(short_rating)
          break
      else:
        new_list.append(rating)
    list_a[:] = new_list


#  so I want to find in "list_a" the strings that are in list_b,
#  and if it is there replace the hole string with what string found it from list_b.
#  so the change should look like this in the end.
#  list_a =['PG', 'TV-PG']

replace_list(list_a, list_b)

print('list_a after replace_list', list_a, '\n')