Seven values are given to you, one per line of the input, each written as a Python
expression — a list, a tuple, a set or a range. Read them in this order with
eval(input()):
int_iterable — an iterable of integers (e.g. range(1, 10, 3))string_iterable — an iterable of strings (e.g. ["Apple", "Orange", "Banana"])some_value — a single value (e.g. 4)some_collection — an ordered collection of at least three items (e.g. [1, 2, 3, 4])some_iterable, 6. another_iterable, 7. yet_another_iterable — any three iterablesNow assign each of the variables below. Nothing has to be printed; the variables themselves are graded.
Collection literals
empty_list, empty_set, empty_tuple — an empty list, an empty set and an empty tuple. Careful: {} is an empty dict, not an empty set.singleton_list, singleton_set, singleton_tuple — a list, a set and a tuple holding exactly one element.a_falsy_list, a_falsy_set — a list and a set for which bool(...) is False.a_truthy_tuple — a tuple for which bool(...) is True.Aggregating int_iterable
int_iterable_min, int_iterable_max, int_iterable_sum, int_iterable_len — its smallest value, its largest value, the sum of its values and how many values it has.int_iterable_sorted — a list of its values in ascending order.int_iterable_sorted_desc — a list of its values in descending order.int_iterable_reversed — a list. If int_iterable is a list, reverse it with reversed(); other iterables are not all reversible, so in that case sort it ascending first and reverse that.Indexing and slicing some_collection
third_last_element — the third element from the end, but only if some_collection is a list or a tuple; otherwise None (sets are not indexable).odd_index_elements — the elements at the odd indices 1, 3, 5, …, keeping the type of some_collection, if it is a list, tuple or range; otherwise None.is_some_value_in_some_collection — True if some_value is in some_collection.is_some_value_in_even_indices — True if some_value appears at one of the even indices 0, 2, 4, … of some_collection, if it is a str, list or tuple; otherwise None.Combining the rest
all_iterables — a single list holding the items of some_iterable, then another_iterable, then yet_another_iterable.all_concat — the strings of string_iterable joined with - between them. If string_iterable is a list, keep its order; otherwise it is unordered, so sort the strings first.The input is read for you. Assign the answers to empty_list, empty_set, empty_tuple, singleton_list, singleton_set, singleton_tuple, a_falsy_list, a_falsy_set, a_truthy_tuple, int_iterable_min, int_iterable_max, int_iterable_sum, int_iterable_len, int_iterable_sorted, int_iterable_sorted_desc, int_iterable_reversed, third_last_element, odd_index_elements, is_some_value_in_some_collection, is_some_value_in_even_indices, all_iterables, all_concat.
You do not need to print anything — the values you assign to those names are what gets checked, in that order.
Input
range(1, 10, 3)
['Apple', 'Orange', 'Banana']
4
[1, 2, 3, 4]
(1, 2, 3)
[10, 20]
range(1, 5)
Output
[]
set()
()
[1]
{1}
(1,)
[]
set()
(1,)
1
7
12
3
[1, 4, 7]
[7, 4, 1]
[7, 4, 1]
2
[2, 4]
True
False
[1, 2, 3, 10, 20, 1, 2, 3, 4]
'Apple-Orange-Banana'