Some Basic Python Tuple Programs-3

Python program to find the minimum and maximum value in a list of tuples

  • The built-in max() function returns the largest element in an iterable.
  • The built-in min() function returns the smallest element in an iterable.
  • The zip() built-in method returns an iterator of tuples, grouping the similar index of multiple sequences so that they can be used as a single entity.
  • The ‘*’ operator unpacks every element of an iterable to other variables dynamically.
  • The built-in map() function applies a given function to each element of an iterable and returns a list of the results.
  • The tuple() built-in method takes an iterable and creates a new tuple of its elements.

Python program to get the minimum difference in Tuple pair

  • List comprehension is a compact method that defines a list and its contents at the same time. Its basic syntax consists of a square bracket with an expression that is executed for each element along with for loop to iterate over each element. Read more: List Comprehension in Python – Explained with Examples
  • The built-in abs() function returns the absolute value of a number.

Python program to get the union of Tuples

  • The ‘+’ operator joins multiple tuples together.
  • The set() built-in method creates a set of the iterable passed. A set in python represents a mathematical notion of a set and performs set operations like union, intersection, difference, etc. It is an unordered collection of immutable and unique elements in python. Read more: Set Data Type in Python

Python program to perform AND operation between Tuples

  • The lambda function is a function that is defined without a name. It can have any number of arguments but only one expression as it is a small function having a single line of code. The expression is evaluated and returned.
  • The & operator performs bitwise and operation between elements of the tuples having similar indexes. It returns 1 if both the bits are 1, otherwise, it returns 0.

Python program to perform XOR operation on tuples

  • The ^ operator performs the bitwise XOR operation between elements of the tuples having similar indexes. It returns 1 if one of the bits is 0 and the other bit is 1. If both the bits are 0 or 1, then it returns 0.

Python program to convert string tuples to list tuples

  • The built-in eval() function evaluates the python string expression passed as an argument runs within the program and returns the result as an integer.

Related Posts-

%d bloggers like this: