Skip to content

Commit a588310

Browse files
committed
Program Changes
1 parent 9baa92c commit a588310

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

other/nth_repeated.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ def count_repeated(sequence: list, nth_repeated: int) -> str:
1010
>>> print(count_repeated(sequence, nth_repeated))
1111
The
1212
"""
13-
if nth_repeated < 1:
14-
return ""
15-
sequence_dict = Counter(sequence)
16-
sequence_value = sorted(sequence_dict.values(), reverse=True)
17-
largest = sequence_value[nth_repeated - 1]
18-
for (key, value) in sequence_dict.items():
19-
if value == largest:
20-
return key
21-
return ""
22-
13+
return "" if nth_repeated < 1 else Counter(sequence).most_common()[nth_repeated - 1][0]
2314

2415
if __name__ == "__main__":
2516
input_sequence = [

0 commit comments

Comments
 (0)