Puzzles 48 to 50
Explore Python puzzles 48 to 50 to understand basic set operations, implement simple Unicode encryption and decryption, and apply the guess-and-check method for algorithm design. Learn how to efficiently check conditions with the any function, perform character shifting using Unicode values, and generate solutions through randomized guessing. These exercises deepen your grasp of Python programming and problem-solving techniques.
We'll cover the following...
Puzzle 48
What is the output of the following code?
Note: Enter the output you guessed. Then, press the Run button, and your new Elo will be calculated. Don’t forget to save your Elo rating.
Basic set operations
After executing the code puzzle, both res1 and res2 store whether the variable crawled_text contains a word from the word_list. Let’s look at the explanation to achieve this both ways.
res1: Themapfunction checks for each elementwordin theword_listwhether thewordis an element of the splitcrawled_text. The defaultsplitfunction divides the string along the whitespaces. The result is iterable with three booleans. There is one for eachwordin the list of wordsword_list. Finally, we check whether one of them isTrue.res2: Theanyfunction checks whether there is an element in the iterable that isTrue. As soon as it finds aTruevalue, this function returnsTrue. Note that it is more efficient