Complete the code to subscribe the consumer to a topic named 'my_topic'.
consumer.subscribe([1])The subscribe method expects a list of topic names. So, ['my_topic'] is correct.
Complete the code to subscribe the consumer to multiple topics: 'topic1' and 'topic2'.
consumer.subscribe([1])The subscribe method requires a list of topic names. So, ['topic1', 'topic2'] is correct.
Fix the error in the code to correctly subscribe the consumer to 'events'.
consumer.subscribe([1])The subscribe method expects a list of topics, so ['events'] is correct. Passing a string alone causes an error.
Fill both blanks to subscribe the consumer to topics starting with 'data_' and print the subscription list.
topics = ['data_1', 'data_2', 'logs'] filtered = [topic for topic in topics if topic.[1]('data_')] consumer.subscribe([2]) print(consumer.subscription())
Use startswith to filter topics starting with 'data_'. Then subscribe using the filtered list.
Fill all three blanks to subscribe the consumer to topics with length greater than 5 and print the subscription.
topics = ['alpha', 'beta', 'gamma', 'delta123'] long_topics = [topic for topic in topics if len(topic) [1] 5] consumer.subscribe([2]) print([3].subscription())
Use > to filter topics longer than 5 characters, subscribe using long_topics, and print the consumer's subscription.