A newcomer wants an issue to start with. Triage a list of issues for them.
What to build
A program that picks up to three good first issues from a list.
Requirements
- Each issue is a line
ID|LABELS|COMMENTS|ASSIGNEE. LABELS are separated by commas (and may be empty), COMMENTS is a number, and ASSIGNEE is a name or-for nobody. - An issue is a candidate if it has the label
good first issue. A candidate is eligible if it has no assignee and neither the labelwontfixnorduplicate. - Sort the eligible issues by fewest comments, then by smaller ID. Print up to the first 3 as
#ID (C comment(s)). If there are none, printnone found. - Finally print
skipped: K, where K is the number of candidates that are not eligible.
Input
The first line has n (1 to 100). Each of the next n lines is an issue.
Output
Up to three issue lines (or none found), then the skipped line.
Constraints
1 ≤ n ≤ 100, IDs and comment counts are whole numbers.
Example
Input:
5
12|bug,good first issue|3|-
15|good first issue|0|-
20|enhancement|1|-
31|good first issue,help wanted|7|-
33|good first issue|2|maria
Output:
#15 (0 comment(s))
#12 (3 comment(s))
#31 (7 comment(s))
skipped: 1
Why it works
Filtering gives the eligible list, sorting with numbers (not text) puts the quietest issues first, and counting the candidates that were left out tells the learner how many were not available.
Examples
5 12|bug,good first issue|3|- 15|good first issue|0|- 20|enhancement|1|- 31|good first issue,help wanted|7|- 33|good first issue|2|maria
#15 (0 comment(s)) #12 (3 comment(s)) #31 (7 comment(s)) skipped: 1
2 4|bug|5|- 9|docs|0|-
none found skipped: 0
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Split each line with line.split("|"); the labels are split again with ",".
Hint 2
An issue is eligible if it has "good first issue", no assignee ("-") and neither "wontfix" nor "duplicate".
Hint 3
Sort the eligible issues by (comments, id) with integers, print up to 3, and count the skipped ones.
Solution
Show one correct solution (try it yourself first)
n = int(input())
eligible = []
skipped = 0
for _ in range(n):
issue_id, labels, comments, assignee = input().split("|")
labels = [label.strip() for label in labels.split(",")]
if "good first issue" not in labels:
continue
if assignee.strip() != "-" or "wontfix" in labels or "duplicate" in labels:
skipped += 1
continue
eligible.append((int(comments), int(issue_id)))
eligible.sort()
for comments, issue_id in eligible[:3]:
print(f"#{issue_id} ({comments} comment(s))")
if not eligible:
print("none found")
print(f"skipped: {skipped}")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step