Python Articles

Page 848 of 854

Python program to find Intersection of two lists?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 631 Views

Intersection operation means, we have to take all the common elements from List1 and List 2 and all the elements store in another third list. List1::[1, 2, 3] List2::[2, 3, 6] List3::[2, 3] Algorithm Step 1: input lists. Step 2: first traverse all the elements in the first list and check with the elements in the second list. Step 3: if the elements are matched then store in third list. Example code #Intersection of two lists def intertwolist(A, B): C = [i for i in A if i in B] ...

Read More

Python program to convert an array to an ordinary list with the same items

Arushi
Arushi
Updated on 30-Jul-2019 192 Views

The array is given. Our task is to convert an array to an ordinary list. We solve this problem with the help of tolist() function. This function return the array as a (possibly nested) list. Algorithm Step 1: Given an array. Step 2: convert the array to a list using tolist() function. Step 3: Display list Example Code #Python program to convert an array to an ordinary #list with the same items from array import * def arraytolist(A): lst = A.tolist() # list print("The List Is ::>",lst) # Driver code A= array('i', [20,30,60]) # array arraytolist(A) Output The List Is ::> [20, 30, 60] The List Is ::> [20, 30, 60]

Read More

Inplace operator in Python

Samual Sam
Samual Sam
Updated on 30-Jul-2019 6K+ Views

Definition - In-place operation is an operation that changes directly the content of a given linear algebra, vector, matrices(Tensor) without making a copy. The operators which helps to do the operation is called in-place operator. Eg: a+= b is equivalent to a= operator.iadd(a, b) There are some operators are used for In-place operation. iadd() This function is used to assign the current value and add them. This operator does x+=y operation. In case of strings, numbers assigning is not performed. Example a =operator.iadd(1, 3); print ("The result after adding : ", end="") print(a) Output ...

Read More

Python program to generate all possible valid ID address from given string

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 926 Views

String is given. String contains only digit. Our task is to check all possible valid IP address combinations. Here first we check the length of the string then split by ".". Then we check the different combination of ".". Example Input : "255011123222" It's not a valid IP address. Input : 255011345890 Valid IP address is 255.011.123.222 Algorithm Step 1: First check the length of the string. Step 2: Split the string by ".". We will place 3 dots in the given string. W, X, Y, and Z are numbers from 0-255 the numbers cannot be ...

Read More

Python program to find k'th smallest element in a 2D array

Arushi
Arushi
Updated on 30-Jul-2019 539 Views

One n×n user input integer matrix is given and the value of k. Our task is to find out k'th smallest element in a 2D array. Here we use heapq mudule.Heap queue (or heapq) in Python. In Python, it is available using “heapq” module. The technique of this module in python is that each time the smallest of heap element is popped (min heap).nsmallest () method is used to get n least values from a data frame or a series. Example Input Array is:: 10 20 20 40 15 45 40 30 32 33 30 50 ...

Read More

Python program to check whether two lists are circularly identical

Arushi
Arushi
Updated on 30-Jul-2019 811 Views

Here two lists are given. Our task is to check and found weather two given lists are circularly identical or not. Example Input : A = [100, 100, 10, 10, 100] B = [100, 100, 100, 10, 10] Output : True Explanation True as when these elements in the list will circularly rotate then they would be similar to other given list Algorithm Step 1: Create First and Second List. Step 2: Then Lists are converted to map. Step 3: join () method is used for converting the ...

Read More

Python Unicode Database

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 598 Views

The unicodedata module is used to access all of the Unicode characters using Unicode character databases. In this database, there are character properties of all characters. To use this modules, we need to import the unicodedata module in our code. import unicodedata Unicode Database Methods Some modules of the unicodedata module are described here. Module (unicodedata.lookup(name)) − This method is used to lookup the characters by name. When the name is valid, it should return the character. Otherwise it will raise the KeyError. Module (unicodedata.name(chr[, default]))− This method is used to return the name of the given ...

Read More

Pseudo-terminal Utilities in Python

George John
George John
Updated on 30-Jul-2019 2K+ Views

The Pseudo-terminal utility module pty is defined to handle pseudo-terminal concepts. Using this we can start another process, and also can read or write from controlling terminal using programs. This module is highly platform oriented. We should use UNIX systems to perform these operations. To use the pty module, we should import it using − import pty There are some modules of the pty module, these are − Method pty.fork() This method is used to connect the child controlling terminal to pseudo-terminal. This method returns the pid and the fd. The child process gets the pid 0, but ...

Read More

Access to the Shadow Password Database in Python

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 400 Views

To access the UNIX shadow password database, we should use the spwd module. We need enough privileges to access this file. The shadow password database entries are like tuple like object. To use the spwd module, we should import it using − import spwd The attributes of the shadow password database are − Index Attribute & Description 0 sp_nam The Login Name or the username of the user 1 sp_pwd The Encrypted password 2 sp_lstchg Date of last change 3 sp_min Minimal number of days ...

Read More

Python Completion function for GNU readline

Arjun Thakur
Arjun Thakur
Updated on 30-Jul-2019 466 Views

Unix readline module has tab completion mechanism. To get these features, we have to use rlcompleter module. It can be used in python’s interactive mode. To use this module, we should import it using − import rlcompleter There is a class called Completer class − Method Completer.complete(text, state) This method is used to return the tab completion output. If there is a ‘.’ in the text, then it will try to get all related members of that command. When there is no dot ‘.’ it will just complete the text. Example Code import rlcompleter import sys ...

Read More
Showing 8471–8480 of 8,532 articles
« Prev 1 846 847 848 849 850 854 Next »
Advertisements