Python IMPs
#Simple Program to reverse a string
s="Hello World"
l=s.split(" ") //splits the string from the specified element and returns the rest in list format
print(l)
e=" "
print(e.join(l[::-1]))
Description:
l=["john","harsh"]
x = "#".join(l)
Output: john#harsh
Note:
List to string not possible (Solution is using Join function)
string to list possible using list(string)
string to integer possible
Sorting in List Vs Sorting in String
# Sorting in List
list=[111,2,3,4]
list.sort()
print(list)
#Sorting in String
string="harsh"
sorted(string) //sorts the string in ascending and returns in list form
sorted(string,reverse=True) //descending
//Converting list in string form
res=""
' '.join(string)
Comments
Post a Comment