How can i pass each item in a list into a dictionary and recieve a list of outputs in return?

Wayow

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

Biswajit Paloi

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.

edited at
0

Comments

0 comments
Login to comment

Related

How do I print out each value for a dictionary item in a list

How can I add an item to a list and return a new list

How do I pass multiple dictionary items into a function and return a list?

How to UnitTest a method that recieve and return a list of objects

How can i loop each item of list in each column?

How can I assign new classes to each item in a list by iterating over a dictionary's key/value pairs based on a matched attribute in python?

How can I target each item in a list with collapsible items?

How can I position image before each item in inline list?

How can I loop through a List<T> and grab each item?

How can I add same text to each item of the list?

How can I store the links found for each item searched into a list?

How can I put each item of a list into a particular format?

How can i find an item in a list then return its pair?

How can I pass each value of a list to another subprocess?

How do I get these outputs in 1 single list or dictionary

How can i add a list to a list in a dictionary

Can I get a list item by ref return?

Got a list of items and scores. How do I return a list with the highest item in each subfolder

How can I implement a fuzzy search across each value of a dictionary in a multiple dictionary list?

How can I get the real image value from each item in my list and subscribe it to another list?

How do I generate a list for each list item

need to compare item from first list to every other item in second list and return pass or fail for each check in new list

How can I delete a repeated dictionary in list?

How can I convert a dictionary into a list of tuples?

How can I generate a dictionary from a list?

How can I square the list of numbers in a dictionary?

How can I convert a list to a dictionary

How can I remove an dictionary element in list?

How can I convert a list of words into a dictionary?