How to remove the duplicates:
>>> mylist=["a","b","a","c","c"]
>>> mylist=list(dict.fromkeys(mylist))
>>> print(mylist)
['a', 'b', 'c']
How to remove duplicates through Function
>>> def my_function(x):
... return list(dict.fromkeys(x))
...
>>> mylist=my_function(["a","b","a","c","c"])
>>> print(mylist)
['a', 'b', 'c']
Reverse the String:
>>> txt="Hello World"[::-1]
>>> print(txt)
dlroW olleH
Reverse a String through Function:
>>> def my_function(x):
... return x[::-1]
...
>>> mytxt=my_function("I wonder how this text looks like backwards")
>>> print(mytxt)
sdrawkcab ekil skool txet siht woh rednow I
>>> mylist=["a","b","a","c","c"]
>>> mylist=list(dict.fromkeys(mylist))
>>> print(mylist)
['a', 'b', 'c']
How to remove duplicates through Function
>>> def my_function(x):
... return list(dict.fromkeys(x))
...
>>> mylist=my_function(["a","b","a","c","c"])
>>> print(mylist)
['a', 'b', 'c']
Reverse the String:
>>> txt="Hello World"[::-1]
>>> print(txt)
dlroW olleH
Reverse a String through Function:
>>> def my_function(x):
... return x[::-1]
...
>>> mytxt=my_function("I wonder how this text looks like backwards")
>>> print(mytxt)
sdrawkcab ekil skool txet siht woh rednow I
No comments:
Post a Comment