Skip to content

Commit 198201b

Browse files
authored
Create same_frequency.py
1 parent e22d00b commit 198201b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

FrequencyCounter/same_frequency.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def same_frequency(number1, number2):
2+
str1 = str(number1)
3+
str2 = str(number2)
4+
5+
if not str1 and not str2:
6+
return True
7+
8+
if len(str1) != len(str2):
9+
return False
10+
11+
dict1 = {}
12+
dict2 = {}
13+
14+
for i in str1:
15+
dict1[i] = dict1.get(i, 0) + 1
16+
17+
for i in str2:
18+
dict2[i] = dict2.get(i, 0) + 1
19+
20+
for key in dict1:
21+
if key not in dict2:
22+
return False
23+
if dict2[key] != dict1[key]:
24+
return False
25+
26+
return True

0 commit comments

Comments
 (0)