-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy path14.py
30 lines (21 loc) · 818 Bytes
/
14.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from collections import OrderedDict
# Function to remove all duplicates from string
# and order does not matter
def removeDupWithoutOrder(str):
# set() --> A Set is an unordered collection
# data type that is iterable, mutable,
# and has no duplicate elements.
# "".join() --> It joins two adjacent elements in
# iterable with any symbol defined in
# "" ( double quotes ) and returns a
# single string
return "".join(set(str))
# Function to remove all duplicates from string
# and keep the order of characters same
def removeDupWithOrder(str):
return "".join(OrderedDict.fromkeys(str))
# Driver program
if __name__ == "__main__":
str = "geeksforgeeks"
print("Without Order = ", removeDupWithoutOrder(str))
print("With Order = ", removeDupWithOrder(str))