{"id":20020,"date":"2021-09-06T13:33:23","date_gmt":"2021-09-06T08:03:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=20020"},"modified":"2021-11-22T18:36:28","modified_gmt":"2021-11-22T13:06:28","slug":"python-program-to-get-first-element-of-each-tuple-in-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-get-first-element-of-each-tuple-in-a-list\/","title":{"rendered":"Python Program to get First Element of each Tuple in a List"},"content":{"rendered":"

In the previous article, we have discussed Python Program for Modulo of Tuple Elements<\/a><\/p>\n

Tuple in Python:<\/strong><\/p>\n

A tuple is an immutable list of objects. That means the elements of a tuple cannot be modified or changed while the program is running.<\/p>\n

Given some random number of tuples in a list and the task is to get the first element of each tuple in a given tuple list.<\/p>\n

For example<\/p>\n

let the tuple list = [(1, 2),(3, 4)]<\/p>\n

The first element of tuples in the given list = [1, 3]<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Tuple list = [(1, 2), (3, 4)]<\/pre>\n

Output:<\/strong><\/p>\n

The first element of the each tuple in a given tuplelist [(1, 2), (3, 4)] = [1, 3]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given Tuple list = [('p', 'q', 'r'), ('s', 't'), ('u', 'v')]<\/pre>\n

Output:<\/strong><\/p>\n

The first element of the each tuple in a given tuplelist [('p', 'q', 'r'), ('s', 't'), ('u', 'v')] = ['p', 's', 'u']<\/pre>\n

Program to get the First Element of each Tuple in a List in Python<\/h2>\n

Below are the ways to get the first element of each tuple in a given tuple list:<\/p>\n