Wednesday, May 1, 2024

📑 Cycle Lists

📑 Task

1) What will the program print in the last line?
2) Modify the program so that the same result is produced by a generator function
with arguments: the original list, the starting character, and the length of the resulting list
Suggest variants of code for returning from the resulting list to the original list

📑 Answer

1) ['♗', '♘', '♙', '♔', '♕', '♖', '♗', '♘', '♙', '♔']
2)

📑 Lists with Periodic Patterns

📑 Task

1) Will the program print three separate lists of elements of different types
(letters, numbers, fruit symbols) at least in one of output rows?
2) How can you fix the third and fourth code lines
to get three separate lists of elements of different kinds?

📑 Answer

1) No
In the first case, lists of the required type will be inside tuples
In the second case, tuples of elements of different types will be formed
2)

📑 Boolean Functions for Non-Boolean Objects

📑 Task

1) What will the program print?
2) Explain the result of summation using a code snippet

📑 Answer

1) [] (Ellipsis,) {} {None}, 2, 3, 1
2) sum() calculates the sum of the boolean values (True = 1, False = 0)