Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 74a5690

Browse files
Create Anagram.py
1 parent 808ceed commit 74a5690

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

‎String/Anagram.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the anagram function below.
10+
def anagram(s):
11+
if len(s)%2==1:
12+
return -1
13+
else:
14+
z=int(len(s)/2)
15+
s1=s[:z]
16+
s2=s[z:]
17+
s11=[i for i in s1]
18+
s22=[i for i in s2]
19+
20+
count=0
21+
for i in range(0,z):
22+
if s11[i] not in s22:
23+
count+=1
24+
else:
25+
s22.remove(s11[i])
26+
return count
27+
28+
if __name__ == '__main__':
29+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
30+
31+
q = int(input())
32+
33+
for q_itr in range(q):
34+
s = input()
35+
36+
result = anagram(s)
37+
38+
fptr.write(str(result) + '\n')
39+
40+
fptr.close()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /