Puzzles 48 to 50
Examine the basic set operations, simple unicode encryption, and the guess and check framework in Python.
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.
Press + to interact
Elo
1000
############################### id 390## Puzzle Elo 1755## Correctly solved 60 %#############################words_list = ["bitcoin","cryptocurrency","wallet"]crawled_text = '''Research produced by the University ofCambridge estimates that in 2017,there are 2.9 to 5.8 million uniqueusers using a cryptocurrency wallet,most of them using bitcoin.'''split_text = crawled_text.split()res1 = True in map(lambda word:word in split_text, words_list)res2 = any(word in words_list for word in split_text)print(res1 == res2)
Enter the input below
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
: Themap
function checks for each elementword
in theword_list
whether theword
is an element of the splitcrawled_text
. The defaultsplit
function divides the string along the whitespaces. The result is iterable with three booleans. There is one for eachword
in the list of wordsword_list
. Finally, we check whether one of them isTrue
.res2
: Theany
function checks whether there is an element in the iterable that isTrue
. As soon as it finds aTrue
value, this function returns