-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCheckPermutation.py
39 lines (26 loc) · 889 Bytes
/
CheckPermutation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# For a given two strings, 'str1' and 'str2', check whether they are a permutation of each other or not.
# Permutations of each other
# Two strings are said to be a permutation of each other when either of the string's characters can be rearranged so that it becomes identical to the other one.
# Example:
# str1= "sinrtg"
# str2 = "string"
# The character of the first string(str1) can be rearranged to form str2 and hence we can say that the given strings are a permutation of each other.
# Sample Input 1:
# abcde
# baedc
# Sample Output 1:
# true
from sys import stdin
def isPermutation(string1, string2) :
if sorted(string1) == sorted(string2):
return True
else:
return False
#main
string1 = stdin.readline().strip();
string2 = stdin.readline().strip();
ans = isPermutation(string1, string2)
if ans :
print('true')
else :
print('false')