“Temukan Anagram Python String” Kode Jawaban

Periksa apakah dua string adalah anagram python

if sorted(s1) == sorted(s2): 
	print("The strings are anagrams.") 
else: 
	print("The strings aren't anagrams.")  
Cmndr_Salamander

Anagram 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
--------------------------------------------------------------------------------
Gr@Y_orphan_ViLL@in##

Temukan Anagram Python String

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

Anagram 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)

Nice Nightingale

Jawaban yang mirip dengan “Temukan Anagram Python String”

Pertanyaan yang mirip dengan “Temukan Anagram Python String”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya