How can I exclude certain 'columns' from a list of tuples?

324

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)!

RoadRunner

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I exclude a certain column from showing and how to show columns by field_name?

How can I count a list of tuples from a list of tuples?

How can I exclude a certain class from inheriting property in CSS

How to exclude certain columns from being filtered

How can I send and unpack the list of tuples from python to qml?

How can I create all permutations from a list of tuples in python?

How can I access certain columns in a DataFrame based on a list?

How can I exclude certain salaries and then order by?

How can I extract numeric ranges from 2 columns and print the range from both columns as tuples?

How can I exclude data from list based on another array?

How can I have separate columns of a dataframe out of list of tuples and a list

In Python, how can I combine a set of tuples from a list of given tuples without using itertools?

How to remove lists with certain words from a list of lists or list of tuples?

How can I sum a list of tuples in Haskell?

How can I convert a dictionary into a list of tuples?

How can I printf a list of tuples?

How can I convert a list of tuples into a mask?

How can I split a list of tuples scala

How can I subtract tuples in a list?

How can I exclude certain dates (e.g., weekends) from time series plots?

How can I extract a certain number of items from a list?

How to only get the tuples I want from a list of tuples? [Haskell]

Filter List of Tuples to Exclude from Another List of Tuples which Contains

Can I exclude certain repositories from apt-get upgrade?

How can I extract tuples from a string?

How can I create a dictionary from a list of k:v tuples returned from a SQL query?

How can I exclude code coverage for certain tests

How can I exclude certain values for curve fitting in R?

How can I indent paragraphs, but exclude certain lines for formatting?