Menu
CoddyTech

Recap: Stock Lookup

Lesson 16 of 48 in Coddy's Python for C# Developers course.

challenge icon

Challenge

Beginner

Read six lines: three scanned codes, pen stock, pad stock, and a lookup code. Codes are nonempty lowercase ASCII words; counts are nonnegative. Output four lines: a sorted list of unique scans; a tuple of that list's first and last codes; whether the lookup is a stock key; and its stock count or 0. Only pen and pad belong to the stock mapping, even when other codes were scanned.

C# transfer checkpoint

HashSet uniqueness transfers to set; neither should define the report order without an explicit sort.

C# reference excerpt: executable statements assume using System; type-only excerpts illustrate the declared contract.

var scans = new System.Collections.Generic.HashSet<string> { "pen", "pen" };
Console.WriteLine(scans.Count);

Python pattern

scans = {"pen", "pen"}
print(len(scans))

Editable implementation files: main.py. The locked driver.py is the supplied launcher or input/output harness and must remain unchanged.

Use the supplied input contract without prompts. Print only the required lines, each ending in a newline.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")

All lessons in Python for C# Developers

Practice on your own: Online Python compiler