xxxxxxxxxx
# Basic syntax:
dict_of_counts = {item:your_list.count(item) for item in your_list}
# Example usage:
your_list = ["a", "b", "a", "c", "c", "a", "c"]
dict_of_counts = {item:your_list.count(item) for item in your_list}
print(dict_of_counts)
--> {'a': 3, 'b': 1, 'c': 3}
xxxxxxxxxx
l=[1,2,3,4,5,2,3,4,7,9,5]
l1=[]
for i in l:
if i not in l1:
l1.append(i)
else:
print(i,end=' ')
xxxxxxxxxx
>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
xxxxxxxxxx
def find_duplicates(input_list):
seen = set()
duplicates = set()
for x in input_list:
if x in seen:
duplicates.add(x)
seen.add(x)
return duplicates
# Example usage
my_list = [1, 2, 3, 2, 1, 5, 6, 5, 5, 7]
print(find_duplicates(my_list)) # Output will be {1, 2, 5}