Hints Without Borrow Checking
Lesson 30 of 48 in Coddy's Python for Rust Developers course.
Rust signatures enforce type contracts before execution. Python annotations document intended types and can be checked by separate tooling, but the interpreter does not enforce them automatically. The annotated doubling function still repeats a string when called with one. Python bool is a subclass of int, so an integer instance check also accepts booleans. Use explicit runtime validation if the input contract must reject them. Type hints do not restore Rust ownership, lifetimes, or exclusive borrowing.
Rust excerpt inside main
fn twice(x: i32) -> i32 { x * 2 }
println!("{}", twice(3));
println!("{}", true as i32);Python
def twice(x: int) -> int:
return x * 2
print(twice(3))
print(twice("ha"))
print(isinstance(True, int))Porting trap
A Python annotation such as list[int] is not a runtime element validator. Tests and deliberate checks remain needed at untrusted input boundaries.
Implement the specified API in the editable Python files. The locked driver.py runs the program and supplies input/output. Keep its imports and names unchanged.
Challenge
BeginnerImplement count_at_least(values: list[int], minimum: int) -> int. Return how many integers in the list are at least the minimum, retaining duplicates as separate observations. Preserve the list. Do not print or read input. The driver reads integer tokens on one line and a minimum on the next. It prints the count and then unchanged or changed. Keep the supplied annotations as documentation; behavioral tests do not treat annotations as runtime validation.
Your function definitions go in functions.py. The locked driver.py imports them and handles the supplied input/output and checks. You do not need to edit the driver.
Try it yourself
from functions import count_at_least
values = [int(part) for part in input().split()]
minimum = int(input())
before = values.copy()
print(count_at_least(values, minimum))
print("unchanged" if values == before else "changed")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Python for Rust Developers
1From Rust to Python
Run Your First Python ProgramMacros to printBindings, mut, and ShadowingIntegers and Floor DivisionIndentation and ScopeRecap: Rewrite a Receipt4Iteration and Transformations
Borrowed Iteration to forEntries and enumeratewhile, break, and continueIterators and ComprehensionsRecap: Build a Ranking2Values and Decisions
Option and NoneEquality and Object IdentityTruth Tests and FallbacksIf Expressions and elifRecap: Eligibility Rules3Ownership and Collections
Vec to listTuples and DestructuringHashMap to dictClone and Shallow CopiesRecap: Clean an Inventory6Errors and Modules
Text Input and FormattingResult, Exceptions, and withModules and the Main GuardHints Without Borrow CheckingRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler