Found 34494 Articles for Programming

Python program to find common elements in three lists using sets

AmitDiwan
Updated on 12-Aug-2022 11:44:01

1K+ Views

In this article, we will learn how to find common elements in three lists. The list is the most versatile datatype available in Python, which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type. However, Set is a collection in Python, which is unordered, unchangeable, and unindexed. Let’s say we have the following input − a = [5, 10, 15, 20, 25] b = [2, 5, 6, 7, 10, 15, 18, 20] c = [10, 20, 30, ... Read More

Break a list into chunks of size N in Python

AmitDiwan
Updated on 12-Aug-2022 11:53:11

427 Views

In this example, we will learn how to break a list into chunks of size N. We will be using the list() function here. The list() function creates a list object. A list object is a collection which is ordered and changeable. Break a list into chunks of size N with List Comprehension The List Comprehension can be used to breal a list into chunks of size N − Example A = list() # User input for list size n = int(input("Enter the size of the List")) # User input for number print("Enter the number") for i in range(int(n)): ... Read More

Three way partitioning of an array around a given range using Python

AmitDiwan
Updated on 12-Aug-2022 14:36:50

250 Views

Given an array and the range of the array [startval, endval]. Array is divided by three parts. All elements smaller than startval come first. All elements in range startval to endval come next. All elements greater than endval appear in the end. Let’s say we have the following input − A = [1, 14, 51, 12, 4, 2, 54, 20, 87, 98, 3, 1, 32] startval = 14, endval = 54 The output should be − A = [1, 12, 4, 2, 3, 1, 14, 51, 20, 32, 54, 87, 98] Three-way partitioning of an array around ... Read More

Stack and Queue in Python using queue Module

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

455 Views

In Python, it is very easy to implement stack and queue data structures. Stack is called LIFO because Stack works on the principle of "Last-in, first-out" and Queue is called FIFO because Queue works on the principle of "First-in, first-out", and the inbuilt functions in Python make the code shorter and simple. The Queue module implements multi-producer, multi-consumer queues and It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implements all the required locking semantics and it depends on the availability of thread support in Python. This ... Read More

Extracting MAC address using Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

We know that the MAC address is a hardware address which means it is unique for the network card installed on our PC. It is always unique that means no two devices on a local network could have the same MAC addresses. The main purpose of MAC address is to provide a unique hardware address or physical address for every node on a local area network (LAN) or other networks. A node means a point at which a computer or other device (e.g. a printer or router) will remain connected to the network. Method1 Using uuid.getnode() In this example getnode() ... Read More

How to check if a string is a valid keyword in Python?

AmitDiwan
Updated on 11-Aug-2022 11:45:16

2K+ Views

To check if a string is a valid keyword, import the keyword module and use the iskeyword() method. With that, you can directly display all the keywords at once and verify. Let’s say the following is our input − else The following is the output. The “else” is a keyword in Python − Keyword Check if a string is a valid keyword in Python Example import keyword # Create a List myList = ["for", "amit", "val", "while"] # Display the List print("List = ", myList) keyword_list = [] non_keyword_list = [] # Looping and ... Read More

Send mail from your Gmail account using Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

16K+ Views

In this article, we will see how we can send email with attachments using Python. To send mail, we do not need any external library. There is a module called SMTPlib, which comes with Python. It uses SMTP (Simple Mail Transfer Protocol) to send the mail. It creates SMTP client session objects for mailing. SMTP needs valid source and destination email ids, and port numbers. The port number varies for different sites. As an example, for google the port is 587. At first we need to import the module to send mail. import smtplib Here we are also ... Read More

Tracking bird migration using Python-3

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

269 Views

In some Research works, Researchers uses GPS modules to track the animal behavior. They can track how they are travelling to different places in different time of a year etc. In this example we use that kind of dataset to get an idea, how Birds are moving in different places. In this dataset there are the location details from GPS module are stored. The complete dataset is in CSV form. In that file, there are different fields. The first one is Bird Id, then date_time, Latitude, longitude and speed. For this Task, we need some modules that can be used ... Read More

Shell Sort program in C#

George John
Updated on 27-Jun-2020 06:24:13

686 Views

Shell Sort allows the exchange of items that are far apart in the array and then reduces the gap between them. This is a sort of generalization of Insertion Sort. Shell Sort is known as such as it was published by Donald Shell at first.A program that demonstrates shell sort in C# is given as follows −Example Live Demousing System; namespace ShellSortDemo {    public class Example {       static void shellSort(int[] arr, int n) {          int i, j, pos, temp;          pos = 3;          while (pos > ... Read More

Simple Chat Room using Python

Samual Sam
Updated on 03-Sep-2020 16:10:11

2K+ Views

In this article we will see how to make a server and client chat room system using Socket Programming with Python.The sockets are the endpoints of any communication channel. These are used to connect the server and client. Sockets are Bi-Directional. In this area, we will setup sockets for each end and setup the chatroom system among different clients through the server. The server side has some ports to connect with client sockets. When a client tries to connect with the same port, then the connection will be established for the chat room.There are basically two parts. The server side ... Read More

Advertisements