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

python find if strings are anagrams

def anagram_checker(first_value, second_value):
    if sorted(first_string) == sorted(second_string):
        print("The two strings are anagrams of each other.")
        out = True
    else:
        print("The two strings are not anagrams of each other.")
        out = False
    return out
        

first_string = input("Provide the first string: ")
second_string = input("Provide the second string: ")
anagram_checker(first_string, second_string)

Print(anagram_checker("python", "typhon"))
True
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

finding anagrams in python

is_anagram = lambda x1, x2: sorted(x1) == sorted(x2)

print(is_anagram('silent','listen')) # True
print(is_anagram('elivs', 'dead')) # False
Comment

PREVIOUS NEXT
Code Example
Python :: threshold image segmentation code python 
Python :: visualising centroid of an unsupervised learning algorithm 
Python :: python4 
Python :: django query filter less than 
Python :: words repeating in word cloud python 
Python :: sample k-means clustering 
Python :: python kivy black screen 
Python :: convert matlab code to python 
Python :: python raccourci mettre paragraphe commentaire 
Python :: how to prefix numbers with zero in python 
Python :: appropriate graph for data visualization 
Python :: pyaudio get system audio 
Python :: frame work in turtle module 
Python :: ERROR: Target path exists but is not a directory, will not continue. 
Python :: Custom x, y-ticks using ax 
Python :: Delete files in folder by extension 
Python :: django Account has no customer 
Python :: theano_flags windows 
Python :: trends in yearly data python 
Python :: example of input int questions in python with if statement 
Python :: python on read text execute command 
Python :: how to maximize pandas output python 
Python :: python copy sequence 
Python :: mass algorithm python 
Python :: add fully connected layers at encoder of autoencoder 
Python :: ios iterate through dictionary 
Python :: python slice second element of list of lists 
Python :: use reshape in python with zeros 
Python :: Ornhgvshy vf orggre guna htyl 
Python :: idwt pywt 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =