Complete the code to check if the variable is truthy.
if [1]: print("It's truthy!")
The value 1 is truthy in Python, so the condition passes and prints the message.
Complete the code to print 'Empty' if the list is falsy (empty).
my_list = [] if not [1]: print('Empty')
An empty list is falsy, so not my_list is True and prints 'Empty'.
Fix the error in the code to check if the string is falsy.
text = '' if [1]: print('Not empty') else: print('Empty')
Using len(text) > 0 correctly checks if the string is not empty.
Fill both blanks to create a dictionary of words with their lengths, only for words longer than 3 characters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys, values as word lengths, only for words with length greater than 4.
words = ['apple', 'bat', 'carrot', 'dog'] result = { [1]: [2] for w in words if [3] }
The dictionary comprehension uses uppercase words as keys, their lengths as values, and filters words longer than 4 characters.