Use get() method to Create a Dictionary in Python from a List of Elements Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report We are given a list of elements and our task is to create a dictionary where each element serves as a key. If a key appears multiple times then we need to count its occurrences. get() method in Python helps achieve this efficiently by providing a default value when accessing dictionary keys. For example, given the list: a = ["apple", "banana", "apple", "orange", "banana", "apple"] then we should create the dictionary: {'apple': 3, 'banana': 2, 'orange': 1}Using get()Instead of checking if the key exists we use get() to provide a default count of 0, making the code more concise and efficient. Python a = ["apple", "banana", "apple", "orange", "banana", "apple"] d = {} for item in a: d[item] = d.get(item, 0) + 1 print(d) Output{'apple': 3, 'banana': 2, 'orange': 1} Explanation:d.get(item, 0) retrieves the current count (defaulting to 0 if the key is missing) and we simply add 1 to update the count.This approach removes the need for explicit conditional checks making it cleaner and more efficient. Comment More infoAdvertise with us Next Article How to use a List as a key of a Dictionary in Python 3? R rohanraj19 Follow Improve Article Tags : Python python-dict Python-dict-functions Practice Tags : pythonpython-dict Similar Reads How to use a List as a key of a Dictionary in Python 3? In Python, we use dictionaries to check if an item is present or not . Dictionaries use key:value pair to search if a key is present or not and if the key is present what is its value . We can use integer, string, tuples as dictionary keys but cannot use list as a key of it . The reason is explained 3 min read How to use a List as a key of a Dictionary in Python 3? In Python, we use dictionaries to check if an item is present or not . Dictionaries use key:value pair to search if a key is present or not and if the key is present what is its value . We can use integer, string, tuples as dictionary keys but cannot use list as a key of it . The reason is explained 3 min read How to use a List as a key of a Dictionary in Python 3? In Python, we use dictionaries to check if an item is present or not . Dictionaries use key:value pair to search if a key is present or not and if the key is present what is its value . We can use integer, string, tuples as dictionary keys but cannot use list as a key of it . The reason is explained 3 min read Ways to create a dictionary of Lists - Python A dictionary of lists is a type of dictionary where each value is a list. These dictionaries are commonly used when we need to associate multiple values with a single key.Initialize a Dictionary of ListsThis method involves manually defining a dictionary where each key is explicitly assigned a list 3 min read Ways to create a dictionary of Lists - Python A dictionary of lists is a type of dictionary where each value is a list. These dictionaries are commonly used when we need to associate multiple values with a single key.Initialize a Dictionary of ListsThis method involves manually defining a dictionary where each key is explicitly assigned a list 3 min read Ways to create a dictionary of Lists - Python A dictionary of lists is a type of dictionary where each value is a list. These dictionaries are commonly used when we need to associate multiple values with a single key.Initialize a Dictionary of ListsThis method involves manually defining a dictionary where each key is explicitly assigned a list 3 min read Like