Python3 String List Confusion Clear

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)


# function to check if two strings are
# anagram or not
def check(s1, s2):
     
    # the sorted strings are checked
    if(sorted(s1)== sorted(s2)):
        print("The strings are anagrams.")
    else:
        print("The strings aren't anagrams.")        
         
# driver code 
s1 ="listen"
s2 ="silent"

check(s1, s2)




Comments