Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Анаграммы ( решение 1)
- import string
- string.punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- s = input().lower()
- p = input().lower()
- for i in string.punctuation:
- if i in s:
- s = s.replace(i, '')
- is_anagram = lambda x1, x2: sorted(x1) == sorted(x2)
- if (len(p)> len(s)):
- print('No anagram')
- else:
- list =[]
- start_index = 0
- end_index = len(p)-1
- while (end_index < len(s) ):
- string = s[start_index:end_index+1]
- print(string)
- if is_anagram(string,p):
- list.append(start_index)
- start_index+=1
- end_index+=1
- print(list)
- # решение 2
- from collections import Counter
- import string
- string.punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
- s = input().lower()
- p = input().lower()
- for i in string.punctuation:
- if i in s:
- s = s.replace(i, '')
- def anagram(input1, input2):
- return Counter(input1) == Counter(input2)
- print(anagram(s,p))
- start_index = 0
- end_index = len(p)-1
- while (end_index < len(s) ):
- string = s[start_index:end_index+1]
- if(anagram(string,p)):
- print(str(start_index),end=' ')
- end_index+=1
- start_index+=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement