Answers for "does dictionary in python allow duplicates"

2

switching keys and values in a dictionary in python [duplicate]

my_dict = {2:3, 5:6, 8:9}

new_dict = {}
for k, v in my_dict.items():
    new_dict[v] = k
Posted by: Guest on February-16-2020
0

count repeated strings map python

# Python 3+
import collections
collections.Counter(input_string) # The almost fastest
# Python 2
{key: string.count(key) for key in set(string)} # The second fastest
Posted by: Guest on June-09-2021

Code answers related to "does dictionary in python allow duplicates"

Python Answers by Framework

Browse Popular Code Answers by Language