Code Snippets


def map_strs_to_ints(numbers: list[str]) -> list[int]: 
integers = []
for number in numbers:
integers.append(int(number))
return integers

def remove_negatives(numbers: list[int]) -> list[int]: 
positives = []
for number in numbers:
if number >= 0:
positives.append(number)
return positives

def count(numbers: list[int]) -> int: 
length = 0
for number in numbers:
length = length + 1
return length

def sum(numbers: list[int]) -> int: 
total = 0
for number in numbers:
total += number
return total

def only_questions(words: list[str]) -> list[str]: 
questions = []
for word in words:
if "?" in word:
questions.append(word)
return questions

def last_word(words: list[str]) -> str: 
words = []
last = words[0]
for word in words:
if word > last:
last = word
return last


def check_senior(age: int) -> bool: 
# This `if` statement is unnecessary!
if age > 60:
return True
else:
return False
# Exactly equivalent to
def check_senior(age: int) -> bool:
return age > 60


def check_toddler(age: int): 
# The `== True` part is redundant!
return (age >= 5) == True
def check_toddler(age: int):
# Much better!
return age >= 5



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrev