Tuple XOR Operation in Python

AmitDiwan
Updated on 11-Mar-2021 09:45:54

411 Views

When it is required to perform 'XOR' operations on the elements of one tuple, the 'zip' method and the generator expression can be used.The zip method takes iterables, aggregates them into a tuple, and returns it as the result.Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ( 7, 8, 3, 4, 3, 2) my_tuple_2 = (9, 6, 8, 2, ... Read More

Raise Elements of Tuple as Power to Another Tuple in Python

AmitDiwan
Updated on 11-Mar-2021 09:45:43

304 Views

When it is required to raise the elements of one tuple, as a power of another tuple, the 'zip' method and the generator expression can be used.The zip method takes iterables, aggregates them into a tuple, and returns it as the result.Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ( 7, 8, 3, 4, 3, 2) my_tuple_2 = (9, ... Read More

Concatenation of Two String Tuples in Python

AmitDiwan
Updated on 11-Mar-2021 09:45:03

1K+ Views

When it is required to concatenate two string tuples, the 'zip' method and the generator expression can be used.The zip method takes iterables, aggregates them into a tuple, and returns it as the result.Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.Below is a demonstration of the same −ExampleLive Demomy_tuple_1 = ('Jane', 'Pink', 'El') my_tuple_2 = ('Will', 'Mark', 'Paul') print ("The first tuple is : " ) print(my_tuple_1) ... Read More

Convert Text to Speech in Python

pawandeep
Updated on 11-Mar-2021 09:35:03

976 Views

Converting Text to Speech basically refers to a program where you give input as a text and the output you receive is the input text in the form of a speech.Python offers the text to speech conversion with the help of APIs. One such API which serves this purpose is the Google Text to Speech API , known as gTTS. The gTTS enables to conversion the provided text into speech and save the output as audio.Step 1 − Install gTTSTo use the gTTS Text to speech conversion tool, we need to install it first. Installing the gTTS is pretty easy.Open ... Read More

What is an Object in Python? Explain with Examples

pawandeep
Updated on 11-Mar-2021 09:34:41

4K+ Views

A python is an object-oriented programming language. Almost everything in Python is considered as an object. An object has its own properties(attributes) and behavior(methods).A class is a blueprint of the objects or can be termed as object constructor for creating objects.One class can have many objects and value of properties for different objects can be different.Example of properties and behavior of an objectLet’s take the example of car as an object. Its properties will include its color, company name, year of manufacture , price , mileage etc. The behavior of the car will include the functions it can perform, this ... Read More

Explain Merge Sort in Python

pawandeep
Updated on 11-Mar-2021 09:34:13

1K+ Views

Merge sort is a sorting technique. It is an efficient sorting algorithm with a time complexity of (n logn) where n is the length of the array to be sorted.Merge sort is an algorithm that follows the Divide and Conquers paradigm. It continuously divides the array into two equal halves. Later it starts sorting the lists having a single element each and continuously merges the sorted lists to form the complete sorted list.Hence, we obtain a sorted array.ExampleThe purple boxes and black arrows show the splitting of the list into two halves.The green boxes and red arrows show the merging ... Read More

Get Minimum Difference in Tuple Pair in Python

AmitDiwan
Updated on 11-Mar-2021 09:33:38

398 Views

When it is required to get the minimum different in a tuple pair from a list of tuples, it can be done using the 'min' method and the list comprehension.The list comprehension is a shorthand to iterate through the list and perform operations on it. The 'min' method returns the minimum of values among an iterable.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 a list.Below is a demonstration of the same −ExampleLive Demomy_list = [( 67, 78), ... Read More

Get Maximum of Nth Column from Tuple List in Python

AmitDiwan
Updated on 11-Mar-2021 09:33:11

279 Views

When it is required to get the maximum of 'N'th column from a list of tuples, it can be done using list comprehension and 'max' method.The list comprehension is a shorthand to iterate through the list and perform operations on it. The 'max' method returns the maximum of values among an iterable.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 a list.Below is a demonstration of the same −ExampleLive Demomy_list = [( 67, 78, 39), (34, 23, 52), ... Read More

Find Minimum K Records from Tuple List in Python

AmitDiwan
Updated on 11-Mar-2021 09:32:45

247 Views

When it is required to find the minimum 'k' records from a list of tuples, it can be done using the 'sorted' method and lambda function.The 'sorted' method is used to sort the elements of a list. Anonymous function is a function which is defined without a name.In general, functions in Python are defined using 'def' keyword, but anonymous function is defined with the help of 'lambda' keyword. It takes a single expression, but can take any number of arguments. It uses the expression and returns the result of it.A list can be used to store heterogeneous values (i.e data ... Read More

Explain Python Matrix with Examples

pawandeep
Updated on 11-Mar-2021 09:28:16

4K+ Views

A matrix in Python is a two-dimensional array having a specific number of rows and columns. The data elements in Python matrix can be numbers, strings or symbols etc.Matrix or two-dimensional list is an important data structure. Various operations associated with matrix involve transpose, addition or multiplication of two matrices.We will discuss how to declare a matrix in python with a specific number of rows and columns and then input data items from the user and finally print the matrix.Declare a matrix in Python as nested listA matrix in Python can be declared as a nested list. The number of ... Read More

Advertisements