Skip to content

Commit 8ac047d

Browse files
author
Sarath Kaul
committed
Second repeated changed to nth
1 parent 55f86ea commit 8ac047d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

other/second_repeated.py renamed to other/nth_repeated.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
from collections import Counter
44

55

6-
def second_repeated(sequence: list) -> str:
6+
def second_repeated(sequence: list, nth_repeated: int) -> str:
77
"""
88
>>> sequence = ['Algorithms','Algorithm','Python','Python','The','Python','The']
9-
>>> print(second_repeated(sequence))
9+
>>> nth_repeated = 2
10+
>>> print(second_repeated(sequence, nth_repeated))
1011
The
1112
"""
1213
sequence_dict = Counter(sequence)
1314
sequence_value = sorted(sequence_dict.values(), reverse=True)
14-
second_largest = sequence_value[1]
15+
largest = sequence_value[nth_repeated - 1]
1516
for (key, value) in sequence_dict.items():
16-
if value == second_largest:
17+
if value == largest:
1718
return key
1819
return ""
1920

@@ -31,4 +32,5 @@ def second_repeated(sequence: list) -> str:
3132
"Love",
3233
"Python",
3334
]
34-
print(second_repeated(input_sequence))
35+
nth_repeated = 2
36+
print(second_repeated(input_sequence, nth_repeated))

0 commit comments

Comments
 (0)