Question: PYTHON 3 If I have a list of list, how do I concatenate certain elements together? example: contents = [ ['queue', 'contents'], ['submit', '1', '%turkey',

PYTHON 3

If I have a list of list, how do I concatenate certain elements together?

example:

contents = [ ['queue', 'contents'], ['submit', '1', '%turkey', 'wrap', 'large', 'coffee%', '8.25'], ['next', 'order'], ['submit', '2', '%mushroom', 'soup', 'chocolate', 'dip', 'donut%', '7.59'], ['next', 'order'], ['submit', '3', '%ham', 'and', 'swiss', 'chocolate', 'milk%', '8.29'], ['queue', 'contents'], ['sleep', '4'], ['complete'], ['submit', '4', '%grilled', 'cheese', 'turkey', 'wrap%', '15.42'], ['sleep', '2'], ['complete'], ['queue', 'contents'], ['modify', '3', '%large', 'coffee%', '2.95'], ['sleep', '2'], ['complete'], ['queue', 'contents'], ['cancel', '1'], ['next', 'order'], ['submit', '5', '%potato', 'wedges', 'large', 'coffee%', '8.65'], ['queue', 'contents'], ['submit', '6', '%steak', 'wrap', 'medium', 'coffee%', '9.39'], ['sleep', '3'], ['queue', 'contents'], ['submit', '7', '%chicken', 'noodle', 'soup%', '3.25'], ['queue', 'contents'], ['modify', '1', '%donut%', '.99'], ['cancel', '6'], ['submit', '8', '%turkey', 'wrap', 'large', 'coffee%', '8.25'], ['cancel', '4'], ['queue', 'contents'], ['cancel', '8'], ['queue', 'contents']]

How can I concatenate all the elements between the string starting with "%" and the string that ends with "%" (strings with "%" included)?

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!