Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

anagrams string python

# anagram in string
a1=input('Enter the first string :')
a2=input('Enter the second string :')
b1=sorted(a1)
b2=sorted(a2)
print(b1,b2)
if b1==b2:
 print('They are anagrams')
else:
 print('They are not anagrams')
#output:
--------------------------------------------------------------------------------
case I
Enter the first string :789
Enter the second string :987
['7', '8', '9'] ['7', '8', '9']
They are anagrams
--------------------------------------------------------------------------------
case II
nter the first string :1598
Enter the second string :6951
['1', '5', '8', '9'] ['1', '5', '6', '9']
They are not anagrams
--------------------------------------------------------------------------------
Comment

anagrams string python


def isAnagram(str1, str2):
    str1_list = list(str1)
    str1_list.sort()
    str2_list = list(str2)
    str2_list.sort()

    return (str1_list == str2_list)

Comment

find anagrams of a string python

def are_anagrams(first, second):
    return len(first) == len(second) and sorted(first) == sorted(second)
Comment

PREVIOUS NEXT
Code Example
Python :: sort dict 
Python :: __lt__ 
Python :: create array of specific size python 
Python :: restart python after script execution 
Python :: raise_for_status() requests 
Python :: python tkinter button image 
Python :: how to write a dataframe to s3 object in python 
Python :: ajouter element liste python 
Python :: django cleanup 
Python :: isnotin python 
Python :: python how to drop columns from dataframe 
Python :: how to see directory from os module 
Python :: argparse accept only few options 
Python :: split string python 
Python :: post list python 
Python :: python slice list 
Python :: keras conv2d 
Python :: python if elif 
Python :: python conditions 
Python :: queue in python 
Python :: python ternary elif 
Python :: python list index() 
Python :: Appending rows to a DataFrame 
Python :: ip address finder script python 
Python :: flask rest api upload image 
Python :: how to change the name of a variable in a loop python 
Python :: exit code python 
Python :: python split string with a seperator 
Python :: convert int to string python 
Python :: django queryset multiple filters 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =