Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1341 of 3366
247 Views
When it is required to filter the tuples by the 'K'th element from a list, list comprehension and 'in' operators 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 a list. The 'in' operators checks to see if the specific data is present in the iterable/data or not.The list comprehension is a shorthand to iterate through the list and perform operations on it.Below is a demonstration of the same −ExampleLive Demomy_list = [(1, 21), (25, 'abc', ... Read More
539 Views
We can develop games in Python using PyGame. PyGame is a Python module that is used to develop games. This module includes computer graphics and sound libraries used in video game development.Install PyGameTo develop game in Python, we need PyGame. Therefore, we need to install PyGame.We should Python and pip preinstalled on our system before installing PyGame.Open the terminal and type the following command to install PyGame.py -m pip install -U pygame --userImport PyGameThe PyGame module needs to be imported in Python IDE before writing the program for the game. There is some common code that includes displaying the pygame ... Read More
3K+ Views
When it is required to perform tuple division in Python, the 'zip' method and generator expressions 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, 1, 4) print ("The ... Read More
2K+ Views
The list is a linear data structure containing data elements.Example1, 2, 3, 4, 5, 6Dictionary is a data structure consisting of key: value pairs. Keys are unique and each key has some value associated with it.Example1:2, 3:4, 5:6Given a list, convert this list into the dictionary, such that the odd position elements are the keys and the even position elements are the values as depicted in the above example.Method 1 − Iterating over the listExample Live Demodef convert(l): dic={} for i in range(0, len(l), 2): dic[l[i]]=l[i+1] return dic ar=[1, 'Delhi', 2, 'Kolkata', 3, ... Read More
177K+ Views
Matplotlib is a Python library that helps to plot graphs. It is used in data visualization and graphical plotting.To use matplotlib, we need to install it.Step 1 − Make sure Python and pip is preinstalled on your systemType the following commands in the command prompt to check is python and pip is installed on your system.To check Pythonpython --versionIf python is successfully installed, the version of python installed on your system will be displayed.To check pippip -VThe version of pip will be displayed, if it is successfully installed on your system.Step 2 − Install MatplotlibMatplotlib can be installed using pip. ... Read More
34K+ Views
OpenCV is a Python library that is used to solve computer vision problems. Computer vision include understanding and analyzing digital images by the computer and process the images or provide relevant data after analyzing the image.OpenCV is an open-source library used in machine learning and image processing. It performs tasks such as recognizing handwritten digits, human faces, and objects.To use OpenCV, we need to install it.Step 1 − Make sure Python and pip is preinstalled on your systemType the following commands in command prompt to check is python and pip is installed on your system.To check Pythonpython --versionIf Python is ... Read More
424 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
311 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
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
988 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