0
0
Data Structures Theoryknowledge~10 mins

Queues in message brokers in Data Structures Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to show the basic operation of a queue in a message broker.

Data Structures Theory
queue = []
queue.append('message1')  # Add message to the queue
next_message = queue[1]()  # Remove message from the queue
Drag options to blanks, or click blank then click option'
Apop
Bpop(0)
Cremove
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() removes the last item, not the first.
Using remove() requires the exact value, not the position.
2fill in blank
medium

Complete the code to check if the queue is empty before processing messages.

Data Structures Theory
if len(queue) [1] 0:
    print('Queue is empty')
Drag options to blanks, or click blank then click option'
A==
B>
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' checks for non-empty queue.
Using '>' or '<' does not specifically check for empty.
3fill in blank
hard

Fix the error in the code that tries to add a message to the queue.

Data Structures Theory
queue = []
queue[1]('new_message')
Drag options to blanks, or click blank then click option'
Aadd
Bpush
Cinsert
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' or 'push' which are not list methods in Python.
Using 'insert' requires an index argument.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps messages to their lengths, but only for messages longer than 5 characters.

Data Structures Theory
{message: len(message) for message in messages if len(message) [1] 5}
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' selects shorter messages.
Using '==' selects only messages exactly 5 characters long.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps uppercase messages to their lengths, but only for messages containing the letter 'a'.

Data Structures Theory
{message[1]: len(message), for message in messages if 'a' [2] message}
Drag options to blanks, or click blank then click option'
A.upper()
B,
Cin
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in' for substring check.
Missing the comma between key and value in the dictionary.