Reputation: 91
I call data from Google Sheets, I get an answer in the form of a dictionary with a nested dictionary, since I have two strings combined, the response from the server returns empty strings, how can I get the edited response and write it to a new list?
{'majorDimension': 'COLUMNS',
'range': "'Sheet1'!A3:A964",
'values': [['Sticker | Fnatic | 2020 RMR',
'',
'Sticker | Fnatic (Holo) | 2020 RMR',
'',
'Sticker | FaZe | 2020 RMR',
'',
'Sticker | FaZe (Holo) | 2020 RMR',
'',
'Sticker | TYLOO | 2020 RMR',
'',
'Sticker | TYLOO (Holo) | 2020 RMR',
'',
'Sticker | G2 | 2020 RMR',
'',
'Sticker | G2 (Holo) | 2020 RMR',
'',
'Sticker | Ninjas in Pyjamas | 2020 RMR',
'',
'Sticker | Ninjas in Pyjamas (Holo) | 2020 RMR',
'',
'Sticker | Astralis | 2020 RMR',
'',
'Sticker | Astralis (Holo) | 2020 RMR',
'',
'Sticker | Natus Vincere | 2020 RMR',
'',
'Sticker | Natus Vincere (Holo) | Katowice 2015']]}
I need:
new_list =
['Sticker | Fnatic | 2020 RMR',
'Sticker | Fnatic (Holo) | 2020 RMR',
'Sticker | FaZe | 2020 RMR',
'Sticker | FaZe (Holo) | 2020 RMR',
'Sticker | TYLOO | 2020 RMR',
'Sticker | TYLOO (Holo) | 2020 RMR',
'Sticker | G2 | 2020 RMR',
'Sticker | G2 (Holo) | 2020 RMR',
'Sticker | Ninjas in Pyjamas | 2020 RMR',
'Sticker | Ninjas in Pyjamas (Holo) | 2020 RMR',
'Sticker | Astralis | 2020 RMR',
'Sticker | Astralis (Holo) | 2020 RMR',
'Sticker | Natus Vincere | 2020 RMR',
'Sticker | Natus Vincere (Holo) | Katowice 2015']
Upvotes: 1
Views: 72
Reputation: 96
You can filter it out using filter()
new_list = list(filter(None, c['values'][0]))
Upvotes: 2
Reputation: 2692
Simple list comprehension with checker will do the job (assuming data is the name of variable that the response is being stored):
new_ls = [each for each in data['values'][0] if each != '']
new_ls
would look like:
['Sticker | Fnatic | 2020 RMR', 'Sticker | Fnatic (Holo) | 2020 RMR', 'Sticker | FaZe | 2020 RMR', 'Sticker | FaZe (Holo) | 2020 RMR', 'Sticker | TYLOO | 2020 RMR', 'Sticker | TYLOO (Holo) | 2020 RMR', 'Sticker | G2 | 2020 RMR', 'Sticker | G2 (Holo) | 2020 RMR', 'Sticker | Ninjas in Pyjamas | 2020 RMR', 'Sticker | Ninjas in Pyjamas (Holo) | 2020 RMR', 'Sticker | Astralis | 2020 RMR', 'Sticker | Astralis (Holo) | 2020 RMR', 'Sticker | Natus Vincere | 2020 RMR', 'Sticker | Natus Vincere (Holo) | Katowice 2015']
Upvotes: 1