Problem 8-Anagram Check Analysis Using Python - Competitive Programming

preview_player
Показать описание
All Playlist In My channel

Please donate if you want to support the channel through GPay UPID,

Please join as a member in my channel to get additional benefits like materials in Data Science, live streaming for Members and many more

Please do subscribe my other channel too

Connect with me here:
Рекомендации по теме
Комментарии
Автор

Revise Competitive Programming Playlist

krishnaik
Автор

def anagram(str1, str2):

# convert capital to lower
str1 = str1.lower()
str2 = str2.lower()

#cleaning up spaces in string
str1 = str1.replace(" ", "")
str2 = str2.replace(" ", "")

#convert string to list which includes specific letters
list_str1 = list(str1)
list_str2 = list(str2)
anagram_not_exit = 0

for i in list_str1:
if i in list_str2:
pass
else:
anagram_not_exit+=1


for i in list_str2:
if i in list_str1:
pass
else:
anagram_not_exit+=1

if anagram_not_exit>0:
print('Anagram Does Not Exist')
else:
print('Anagram Exist')

shivamjindal
Автор

def anagram_check(s1, s2):
s1=s1.replace(' ', '').lower()
s2=s2.replace(' ', '').lower()


check={}

for letter in s1:
if letter in check:
check[letter]+=1
else:
check[letter]=1

for letter in s2:
if letter in check:
check[letter]-=1
else:
check[letter]=1


for count in check:
if check[count]!=0:
return 'Not an Anagram'
else:
return 'It is an Anagram'

yashwanthvb
Автор

def check(str1, str2):
if(sorted(str1)== sorted(str2)):
print(" strings are anagram.")
else:
print(" strings aren't anagrams ")
str1 ="study"
str2 ="dusty"
check(str1, str2)

#sorted method returns the sorted string.

govindsingh
Автор

How about this ? I guess it solves the problem in O(n)

str1='Eleven7 plus two'
str2='Twelve77 plus one'
def anagram(str1, str2):
str1=str1.replace(' ', '').lower()
str2=str2.replace(' ', '').lower()
count=0
if len(str1)==len(str2):
for i in str1:
if i in str2:
count+=1
str2=str2.replace(i, '', 1)
else:
return False
else:
return False
if count==len(str1):
return True

fracturedillusions
Автор

Hi krish, i get on one Interview question, it was about decision trees :how tthe decision tree knows, What feature is in the first Node? This is Basic question the tree goes over All features, but I Red that decision tree set the most important features at the beginning of tree, Thanks for your answer

lpis
Автор

check weather Counter() (import it from collections) of both the words are same or not

nishu
Автор

def anagram(str1, str2):
a = sorted(str1.lower().replace(' ', ''))
b = sorted(str2.lower().replace(' ', ''))
if a == b:
return True
else:
return False

theoutlet
Автор

def Anagram(str1, str2):
dict = {}
for i in range(len(str1)):
if ord(str1[i]) <= 122 and ord(str1[i])>=97:
if ord(str1[i])-32 not in dict:
dict[ord(str1[i])-32] = 1
else:
dict[ord(str1[i])-32] = dict[ord(str1[i])-32] + 1
else:
if ord(str1[i]) not in dict:
dict[ord(str1[i])] = 1
else:
dict[ord(str1[i])] = dict[ord(str1[i])] + 1

for i in range(len(str2)):
if ord(str2[i])<=122 and ord(str2[i])>=97:
if ord(str2[i])-32 in dict:
if dict[ord(str2[i])-32] != 0:
dict[ord(str2[i])-32] = dict[ord(str2[i])-32] - 1
else:
return 0
else:
return 0
else:
if ord(str2[i]) in dict:
if dict[ord(str2[i])] != 0:
dict[ord(str2[i])] = dict[ord(str2[i])] - 1
else:
return 0
else:
return 0

return 1



str1 = input()
str2 = input()
if Anagram(str1, str2):
print("Yes")
else:
print("No")

akhilsoni
Автор

str1 = "eleven plus two"
str2 = "twelve plus one"

def anagram(str1, str2):
str1 = str1.replace(" ", "").lower()
str2 = str2.replace(" ", "").lower()
if len(str1) == len(str2):
for i in str1:
if i in str2:
pass
return True
return False
print(anagram(str1, str2))

sonalighadage
Автор

str1 = input("Enter some text:")
str2 = input("Enter some text:")
str3=str1.lower()
str4=str2.lower()


remove = " "
def remo(c1):
result=""
for i in c1:
if i!=remove:
result+=i
return result
def char_count(value):
count={}
for char in value:
if char in count:
count[char]+=1
else:
count[char] = 1
return count
def aroma(value_1, value_2):
result1=""
result2=""
count1=char_count(value_1)
count2=char_count(value_2)
result1=remo(value_1)
result2=remo(value_2)
len1= len(result1)
len2= len(result2)

if len1 != len2:
print("Not anagram")

elif count1==count2:
print("Anagram")
else:
print("sorry not anagram")

aroma(str3, str4)

jannatfardus
Автор

Str1 = input ('string1')
Str2= input ('string2')
If len(str1) == len(str2):
If sorted (str1)== sorted (str2):
Print('given string is anagrams')
Else:
Print ('given string are not anagrams')
Else:
Print('given string are not anagrams')
Sir this way is right to to do it

dataanalyticsfun
Автор

my solution. Although not optimized for competitive programming. Suggestions to improve further?

def counter_fn(str_char):
str_char = str_char.replace(" ", "").lower()
count_dict = {}
for entry in str_char:
if entry in count_dict.keys():
count_dict[entry] += 1
else:
count_dict[entry] = 1
return count_dict

if __name__ == '__main__':
str_1 = input()
str_2 = input()
count_dict1 = counter_fn(str_1)
count_dict2 = counter_fn(str_2)
if count_dict1 == count_dict2:
print('ANAGRAM')
else:
print('NOT ANAGRAM')

KisaanTuber
Автор

I need someone to help me in my Python homeworks for free...😭😭

Mujahidabbastarar
join shbcf.ru