-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.py
More file actions
37 lines (29 loc) · 779 Bytes
/
lambda.py
File metadata and controls
37 lines (29 loc) · 779 Bytes
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
import json
def lambda_handler(event, context):
str1 = event['str1'].lower()
str2 = event['str2'].lower()
if len(str1) != len(str2):
return {
'statusCode': 200,
'body': json.dumps({'result': 'Not anagrams (lengths differ)'})
}
char_counts1 = {}
char_counts2 = {}
for char in str1:
char_counts1[char] = char_counts1.get(char, 0) + 1
for char in str2:
char_counts2[char] = char_counts2.get(char, 0) + 1
if char_counts1 == char_counts2:
return {
'statusCode': 200,
'body': json.dumps({'result': 'Anagrams'})
}
else:
return {
'statusCode': 200,
'body': json.dumps({'result': 'Not anagrams'})
}
event = {
'str1': 'listen',
'str2': 'silent'
}