Search⌘ K
AI Features

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.

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.

Python 3.5
#############################
## id 390
## Puzzle Elo 1755
## Correctly solved 60 %
#############################
words_list = ["bitcoin",
"cryptocurrency",
"wallet"]
crawled_text = '''
Research produced by the University of
Cambridge estimates that in 2017,
there are 2.9 to 5.8 million unique
users 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)
Did you find this helpful?

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: The map function checks for each element word in the word_list whether the word is an element of the split crawled_text. The default split function divides the string along the whitespaces. The result is iterable with three booleans. There is one for each word in the list of words word_list. Finally, we check whether one of them is True.
  • res2: The any function checks whether there is an element in the iterable that is True. As soon as it finds a True value, this function returns True. Note that it is more efficient
...