Skip to content

Commit f147025

Browse files
committed
handling invalid topic argument
1 parent 8855efe commit f147025

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lcpp.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def load_user_data():
3434
return load_json('user.json')
3535

3636
def pick_problems(user_data, problems, topic_list, k=5, problem_type=ProblemType.Random):
37-
selected_topics = set(itertools.chain(*[topics[topic] for topic in topic_list]))
37+
selected_topics = set(itertools.chain(*[topics.get(topic,[]) for topic in topic_list]))
3838

3939
skip_set = set(load_completed_list(user_data))
4040
for maybe_skip in ['hard', 'revisit', 'refresh']:
@@ -100,6 +100,13 @@ def mark_problem(user_data, mark_type, leetcode_id):
100100
problems = pick_problems(user_data, problems=problem_set, topic_list=args.topic_list, k=args.num_problems)
101101
problem_set -= set(problems)
102102

103+
if len(problems) == 0:
104+
print("You have completed all the problems in the selected set. Re-picking from the entire problem set")
105+
problems = pick_problems(user_data, problems=set(range(1,1700)), topic_list=args.topic_list, k=args.num_problems)
106+
if len(problems) == 0:
107+
print("Your --topic_list is either invalid or all completed. Repicking from all topics.")
108+
problems = pick_problems(user_data, problems=problem_set, topic_list=topics.keys(), k=args.num_problems)
109+
103110
valid_inputs = ["info", "hint", "easy", "hard", "quit", "pause", "break"]
104111
print(f"Other valid inputs: {', '.join(valid_inputs)}")
105112

0 commit comments

Comments
 (0)