Hopefully this is pretty simple to solve (I'm pretty new to this). I have a dataset of different regions. Here is a sample
Name Customers Online Customers
Brandon Park 57 43
Heritage 29 20
Between the Hills 33 12
...
This is stored in a list of tuples (i.e., [(Brandon Park, 57, 43), (Heritage, 29, 20), ...]
I want to have a list of tuples that excluded the Online Customers section, so that my list of tuples becomes [(Brandon Park, 57), (Heritage, 29), ...]
(notice there are only two entries in each tuple now).
I've tried various things, but none of them are getting me to the correct answer (many errors)!
You can exclude the last column in a list comprehension:
>>> l = [('Brandon Park', 57, 43), ('Heritage', 29, 20)]
>>> [(name, customer) for name, customer, online_customer in l]
[('Brandon Park', 57), ('Heritage', 29)]
As you can see the last column online_customer
is not included in the final result, and new tuples with (name, customer)
are only included.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments