Question: #THIS IS THE CODE: tv = [ 'r24_getrenderingmode', 'r24_panel', 'r24_pcpar', 'Literal question:', 'Which party would you vote for today?', 'r24_pcpar_13_other', 'Literal question:', 'Other:', 'Post question:',

#THIS IS THE CODE: tv = [ 'r24_getrenderingmode', 'r24_panel', 'r24_pcpar', 'Literal question:', 'Which party would you vote for today?', 'r24_pcpar_13_other', 'Literal question:', 'Other:', 'Post question:', 'KIWI:', 'r24_pcpak', 'r24_pcpak_16_other', 'r24_pcpaf', 'Literal question:', 'Which party would you vote for?', ] rex = [] for i in tv: if i[0] == "r": rex.append(i) for i in range(len(tv)-1): if tv[i+1] in rex: print(tv[i]) if tv[i+1] not in rex: print("", tv[i]) 

The output is:

r24_getrenderingmode r24_panel r24_pcpar Literal question: Which party would you vote for today? r24_pcpar_13_other Literal question: Other: Post question: KIWI: r24_pcpak r24_pcpak_16_other r24_pcpaf Literal question:

How can I modify it so that the last elem not in rex is also included? DESIRED OUTPUT:

r24_getrenderingmode r24_panel r24_pcpar Literal question: Which party would you vote for today? r24_pcpar_13_other Literal question: Other: Post question: KIWI: r24_pcpak r24_pcpak_16_other r24_pcpaf Literal question: Which party would you vote for?

Please make sure your output matches perfectly with the output DESIRED OUTPUT mentioned in the task. Very important!

Thank you

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!