Skip to content

Commit 798a652

Browse files
committed
Update Leetcode Readme title creation
1 parent 088a0dc commit 798a652

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Scripts/update_readmes.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616

1717
nav_entries = []
1818

19+
ROMAN_NUMERALS = {
20+
"i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x",
21+
"xi", "xii", "xiii", "xiv", "xv", "xvi", "xvii", "xviii", "xix", "xx"
22+
}
23+
24+
def smart_capitalize(word: str) -> str:
25+
"""Capitalize a word unless it's a Roman numeral in lowercase."""
26+
if word.lower() in ROMAN_NUMERALS:
27+
return word.upper()
28+
return word.capitalize()
29+
1930
def fetch_question_details(slug: str):
2031
"""Fetch difficulty and tags from LeetCode GraphQL API."""
2132
url = "https://leetcode.com/graphql"
@@ -73,7 +84,7 @@ def tag_badge(tag: str) -> str:
7384
continue
7485
number, title_slug = match.groups()
7586
number = str(int(number))
76-
title = ' '.join([w.capitalize() for w in title_slug.split('-')])
87+
title = ' '.join([smart_capitalize(w) for w in title_slug.split('-')])
7788

7889
readme_path = prob_path / "README.md"
7990
readme_content = ""

0 commit comments

Comments
 (0)