Skip to content

Commit f0edf0f

Browse files
author
Sarath Kaul
committed
Second most repeated character in a sequence
1 parent 0832e1e commit f0edf0f

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

other/second_repeated.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Created by sarathkaul on 04/02/20
2+
# Script to print second most repeated character in sequence
3+
from collections import Counter
4+
5+
6+
def second_repeated(sequence: list) -> str:
7+
"""
8+
>>> sequence = ['Algorithms','Algorithm','Python','Python','The','Python','The']
9+
>>> print(second_repeated(sequence))
10+
The
11+
"""
12+
sequence_dict = Counter(sequence)
13+
sequence_value = sorted(sequence_dict.values(), reverse=True)
14+
second_largest = sequence_value[1]
15+
for (key, value) in sequence_dict.items():
16+
if value == second_largest:
17+
return key
18+
return ""
19+
20+
21+
if __name__ == "__main__":
22+
input_sequence = [
23+
"Python",
24+
"2.7",
25+
"is",
26+
"deprecated",
27+
"Python",
28+
"3+",
29+
"is",
30+
"active",
31+
"Love",
32+
"Python",
33+
]
34+
print(second_repeated(input_sequence))

web_programming/fetch_bbc_news.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
def fetch_bbc_news(bbc_news_api_key: str) -> None:
99
# fetching a list of articles in json format
1010
bbc_news_page = requests.get(_NEWS_API + bbc_news_api_key).json()
11+
print (bbc_news_page)
1112
# each article in the list is a dict
12-
for i, article in enumerate(bbc_news_page["articles"], 1):
13-
print(f"{i}.) {article['title']}")
13+
# for i, article in enumerate(bbc_news_page["articles"], 1):
14+
# print(f"{i}.) {article['title']}")
1415

1516

1617
if __name__ == "__main__":
17-
fetch_bbc_news(bbc_news_api_key="<Your BBC News API key goes here>")
18+
fetch_bbc_news(bbc_news_api_key="4dbc17e007ab436fb66416009dfb59a8")

0 commit comments

Comments
 (0)