Found 10783 Articles for Python

sort() in Python

Hafeezul Kareem
Updated on 11-Jul-2020 06:57:44

275 Views

In this tutorial, we are going to learn about the sort method of a list. Let's dive into the tutorial. The method sort is used to sort any list in ascending or descending order. There are many cases of sort method with or without optional parameters.The method sort is an in-place method. It directly changes in the original listLet's see one by one.Default sort()The method sort without any optional parameters will sort the list in ascending order. Let's an example.Example Live Demo# initializing a list numbers = [4, 3, 5, 1, 2] # sorting the numbers numbers.sort() # printing the numbers ... Read More

Set update() in Python to do union of n arrays

Hafeezul Kareem
Updated on 11-Jul-2020 06:55:48

249 Views

In this tutorial, we are going to write a program that uses set update method to union multiple arrays. And it will return a resultant one-dimension array with all unique values from the arrays.Let's see an example to understand it more clearly.Let's see an example to understand it more clearly.Inputarrays = [[1, 2, 3, 4, 5], [6, 7, 8, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]Output[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]Follow the below steps to write the program.Initialize the array as shown in the example.3Create an empty.Iterate over ... Read More

set copy() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:54:53

211 Views

In this tutorial, we are going to learn about the copy method set data structure. Let's see it in detail.The method copy is used to get a shallow copy of a set.Let's see different examples to under normal and shallow copy of a set.Normal CopyFollow the below steps and understand the output.Initialize a set.Assign the set to another variable with the assignment operator.Now, add one more element to the copied set.Print both sets.You won't find any difference between. The assignment operator returns the set reference. both sets are pointing to the same object in the memory. So, whatever changes made ... Read More

set clear() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:53:42

3K+ Views

In this tutorial, we are going to learn about the clear method of set data structure. Let's see details about the clear method.The method clear is used to clear all the data from the set data structure. All elements from set will clear. And we will leave with an empty set.Follow the below steps to see clear method in action.Initialize a set.User the clear method and clear the set.Print the set and you will see an empty one.Example Live Demo# initialzing a set number_set = {1, 2, 3, 4, 5} # clearing the set number_set.clear() # printing the set print(number_set)OutputIf you ... Read More

set add() in python

Hafeezul Kareem
Updated on 11-Jul-2020 06:51:05

177 Views

In this tutorial, we are going to learn about the add method of set data structure. Let's dive into the tutorial.Set data structure stores unique elements in it. The add method of set data structure takes an element and adds it to the set.Follow the below steps to add a new element to the set.Initialize a set.Add a new element to the set using the add method.Print the updated set.Example Live Demo# initialzing the set numbers_set = {1, 2, 3, 4, 4, 5} # adding an element to the set numbers_set.add(6) # printing the updated set print(numbers_set)OutputIf you run the above ... Read More

Send SMS updates to mobile phone using python

Hafeezul Kareem
Updated on 11-Jul-2020 06:49:54

2K+ Views

In this tutorial, we are going to learn how to send SMS in Python. We will be using Twilio for sending SMS.First of all, go the Twilio and create an account. You will get free trial account. And finish settings.We have to install a module called twilio to work with Twilio client. Install it with the following command.pip install twilioNow, go to the Twilio Documentation on how to send SMS using Twilio client. Or follow the steps to send the SMS.Import the twilio Client from twilio.rest.Get and store the account_sid and auth_token from the your Twilio account.Make instance of the ... Read More

self in Python class

Hafeezul Kareem
Updated on 11-Jul-2020 06:47:23

1K+ Views

In this tutorial, we are going to learn about the self in Python. You must be familiar with it if you are working with Python. We will see some interesting things about.Note − self is not a keyword in Python.Let's start with the most common usage of self in Python.We'll use self in classes to represent the instance of an object. We can create multiple of a class and each instance will have different values. And self helps us to get those property values within the class instance. Let's see ane example.Example# class class Laptop:    # init method   ... Read More

Python - Contiguous Boolean Range

Pradeep Elance
Updated on 10-Jul-2020 11:36:51

266 Views

Given a list of values, we are interested to know at which position are the Boolean values present as a contiguous list. Which means after we encounter a value which is TRUE there is a continuous value of true from that position until FALSE value is found. Similarly when a FALSE is found there is a contiguous value of FALSE until TRUE is found.With itertoolsW can use accumulate along with groupby from the itertools module. In this example we take a given list and then apply the accumulate function to keep track of the values that are brought together using ... Read More

Python - Column deletion from list of lists

Pradeep Elance
Updated on 10-Jul-2020 11:34:40

885 Views

In a list of lists an element at the same index of each of the sublist represents a column like structure. In this article we will see how we can delete a column from a list of lists. Which means we have to delete the element at the same index position from each of the sublist.Using popWe use the pop method which removes the element at a particular position. A for loop is designed to iterate through elements at specific index and removes them using pop.Example Live Demo# List of lists listA = [[3, 9, 5, 1], [4, 6, 1, 2], ... Read More

Python - Check if given words appear together in a list of sentence

Pradeep Elance
Updated on 10-Jul-2020 11:32:49

960 Views

Say we have a list containing small sentences as its elements. We have another list which contains some of the words used in this sentences of the first list. We want to find out if two words from the second list are present together in some of the sentences of the first list or not.With append and for loopWe use the for loop with in condition to check for the presence of words in the lists of sentences. Then we use the len function to check if we have reached the end of the list.Example Live Demolist_sen = ['Eggs on Sunday', ... Read More

Advertisements