AmitDiwan has Published 10744 Articles

Remove tuples having duplicate first value from given list of tuples in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:38:17

630 Views

When it is required to remove tuples that have a duplicate first value from a given set of list of tuples, a simple 'for' loop, and the 'add' and 'append' methods can be used.Below is a demonstration for the same −ExampleLive Demomy_input = [(45.324, 'Hi Jane, how are you'), (34252.85832, ... Read More

Unpacking tuple of lists in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:37:03

381 Views

When it is required to unpack a tuple of list, the 'reduce' method can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are ... Read More

Remove matching tuples in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:35:47

294 Views

When it is required to remove the matching tuples from two list of tuples, the list comprehension can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in ... Read More

Sort tuple based on occurrence of first element in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:35:26

198 Views

When it is required to sort the tuple based on the occurrence of the first element, the dict.fromkeys method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples ... Read More

Removing strings from tuple in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:32:44

685 Views

When it is required to remove the strings froma  tuple, the list comprehension and the 'type' method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in ... Read More

Summation of list as tuple attribute in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:32:21

239 Views

When it is required to get the summation of a list of tuple, the list comprehension and the 'sum' method can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains ... Read More

Grouped summation of tuple list in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:32:00

177 Views

When it is required to find the grouped summation of a list of tuple, the 'Counter' method and the '+' operator need to be used.The 'Counter' is a sub-class that helps count hashable objects, i.e it creates a hash table on its own (of an iterable- like a list, tuple, ... Read More

Reverse each tuple in a list of tuples in Python

AmitDiwan

AmitDiwan

Updated on 13-Mar-2021 05:31:30

306 Views

When it is required to reverse each tuple in a list of tuples, the negative step slicing can be used.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuple basically contains tuples enclosed ... Read More

Python program to check whether the string is Symmetrical or Palindrome

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 13:09:01

2K+ Views

When it is required to check if a string is symmetrical or it is a palindrome, a method can be defined, that uses the ‘while’ condition. Another method is defined to check the symmetry that uses the ‘while’ and ‘if’ conditions too.A palindrome is a number or string, which when ... Read More

Python Program to Determine How Many Times a Given Letter Occurs in a String Recursively

AmitDiwan

AmitDiwan

Updated on 12-Mar-2021 13:04:59

755 Views

When it is required to check the number of times a given letter occurs in a string using recursion, a method can be defined, and an ‘if’ condition can be used.The recursion computes output of small bits of the bigger problem, and combines these bits to give the solution to ... Read More

Advertisements