How to combine a group of lists together
I utilized .get_text() + .split() functions and obtain this: spe= ['$278.86as', 'of', 'Dec', '20,', '2019,', '06:47', 'PST', '-', 'Details'] ['4.7', 'inches'] ['750', 'x', '1334'] ['64', 'GB'] ['2', 'GB'] ['Apple', 'A11', 'Bionic,', 'Hexa-Core,', '(2x', 'Monsoon', '+', '4x', 'Mistral)'] ['5.22', 'ounces'] ['No'] ['No'] ['12', 'MP'] ['7', 'MP'] ['1821', 'mah'] ['No'] ['Yes,', 'on', 'the', 'front'] ['None'] ['iOS', '(Last', 'OS', 'info:', 'IOS', '11)'] ['September', '2017'] They have a shared name 'spe', but no concrete names for each list. If I use spe[0], I can only get all the first element of each list. How can I mix all of these elements into a single list like: ['$278.86as', 'of', 'Dec', '20,', '2019,', '06:47', 'PST', '-', 'Details','4.7', 'inches'..] Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: How to combine a group of lists together
thanks for responding! Now I've solved this problem! My former code is: for j in data: spe = j.get_text() l_spe = spe.split() print(l_spe) Then I get the result: ['$278.86as', 'of', 'Dec', '20,', '2019,', '06:47', 'PST', '-', 'Details'] ['4.7', 'inches'] ['750', 'x', '1334'] ['64', 'GB'] ['2', 'GB'] ['Apple', 'A11', 'Bionic,', 'Hexa-Core,', '(2x', 'Monsoon', '+', '4x', 'Mistral)'] ['5.22', 'ounces'] ['No'] ['No'] ['12', 'MP'] ['7', 'MP'] ['1821', 'mah'] ['No'] ['Yes,', 'on', 'the', 'front'] ['None'] ['iOS', '(Last', 'OS', 'info:', 'IOS', '11)'] ['September', '2017'] Now my code is: for j in data: spe = j.get_text() temp_li.extend(spe.split()) print(temp_li) Then: ['$278.86as', 'of', 'Dec', '20,', '2019,', '06:47', 'PST', '-', 'Details', '4.7', 'inches', '750', 'x', '1334', '64', 'GB', '2', 'GB', 'Apple', 'A11', 'Bionic,', 'Hexa-Core,', '(2x', 'Monsoon', '+', '4x', 'Mistral)', '5.22', 'ounces', 'No', 'No', '12', 'MP', '7', 'MP', '1821', 'mah', 'No', 'Yes,', 'on', 'the', 'front', 'None', 'iOS', '(Last', 'OS', 'info:', 'IOS', '11)', 'September', '2017'] Bravo! -- https://mail.python.org/mailman/listinfo/python-list
Re: How to combine a group of lists together
Thanks! Actually, I neglected that my "print" is in the "for", so I get a group of lists. Now I put the "print" out of the iteration then use .extend to append each list I produce. Finally, print and get my ideal result. Haha, I'm too naive, so is my English. -- https://mail.python.org/mailman/listinfo/python-list