My question is difficult to word, what I mean is:
my_dict = {'a': 1, 'b': 2, 'c': 3}
my_list = ['b', 'a', 'b', 'c', 'c']
my_list_output = some_func(my_list, my_dict)
print(my_list_output)
# [2, 1, 2, 3, 3]
Is there a neat, somewhat readable way to do this? Thanks
Chack this
def some_func(my_dict,my_list):
newList=[my_dict[k] for k in my_list if k in my_dict]
return newList
my_dict = {'a': 1, 'b': 2, 'c': 3}
my_list = ['b', 'a', 'b', 'c', 'c']
my_list_output= some_func( my_dict,my_list)
print (my_list_output)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments