Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Easy Unpack by Katarzyna_Golab
def easy_unpack(elements: tuple) -> tuple:
if len(elements) < 3:
raise ValueError("Input tuple must have at least 3 elements.")
first_element = elements[0]
third_element = elements[2]
second_from_last_element = elements[-2]
result_tuple = (first_element, third_element, second_from_last_element)
return result_tuple
print("Example:")
print(easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)))
# These "asserts" are used for self-checking
assert easy_unpack((1, 2, 3, 4, 5, 6, 7, 9)) == (1, 3, 7)
assert easy_unpack((1, 1, 1, 1)) == (1, 1, 1)
assert easy_unpack((6, 3, 7)) == (6, 7, 3)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 23, 2024
Comments: