#THIS IS THE CODE: tv = [ 'r24_getrenderingmode', 'r24_panel', 'r24_pcpar', ...
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?
Also it is NOT nessesary, but If you could add all the elements in the desired output in a new empty list, and then
make all the elements in the new list, if i[0] = ''•", be added into one element in the list. It should look like this:
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?
Again, you do NOT have to, only if it's not too much trouble for you and you feel like it. If you can just get the code to print out the desired output, I will still give you great reviews.
Business Statistics
ISBN: 9780321925831
3rd Edition
Authors: Norean Sharpe, Richard Veaux, Paul Velleman