4/22/2023

Find duplicated string in python list, sample source code:

 


refer to code:


.


def find_duplicates(input_list):
seen = set()
duplicates = set()
for item in input_list:
if item in seen:
duplicates.add(item)
else:
seen.add(item)
return list(duplicates)

input_list = ["apple", "orange", "banana", "apple", "orange", "grape"]
duplicates = find_duplicates(input_list)
print(duplicates)

>>>>>>>>>>>>>>>>>>
['apple', 'orange']

..


Thank you.

๐Ÿ™‡๐Ÿป‍♂️

No comments:

Post a Comment