Saturday, April 20, 2024

📑 "Join" Effects for Strings

📑 Task

1) What will be the result of launching the program?
2) How can you change the code so that
the number of integers and letters becomes equal?

📑 Answer

1) a0b1c
The program places integers in order (starting from zero)
between the first 3 letters of the Latin alphabet
2)

📑 Arguments of Named Tuples

📑 Task

1) What will be the result of executing the code?
2) Can you modify this function so that
the argument names of named tuples would be small Latin letters?
And if the number of arguments is more than 26
then the program would issue a warning "Use less than 26 arguments"?

📑 Answer

1) vector() vector(x1=1) vector(x1=1, x2=2)
This function creates named tuples "vector"
with an arbitrary number of arguments x1, x2, etc.
2)

📑 Search for Boolean Values

📑 Task

1) What will be the result of the calculation?
2) Can you suggest a program that will explain the result?

📑 Answer

1) The built-in function isinstance(x, int) classifies the values True and False
as integers and this program counts them in the variable integers_found
So the result will be: integers_found = 6; bools_found = 0
2)

📑 Lambda Multipliers

📑 Task

1) What objects does the program create?
2) What will be the result of running the code?
3) Can you suggest improvements of the program?

📑 Answer

1) The program creates a list of lambda functions
2) The code will print out four identical numbers 12
(the lambda functionsmultiplie the arguments equal to 3 by the same factor m=4)
3) To create lambda functions with different multipliers from 1 to m,
in the loop you need to change the definition of the variable "_"