Found 35164 Articles for Programming

Python program to reverse an array in groups of given size?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

490 Views

Here we use one user input array and the size of the group. And we create sub array on the size of the group and we just reverse it. If the size of the groups(p) is not multiple of the size of the array(n) then the last group will less than k elements left and reverse all remaining elements. If p=1 then array is unchanged, if p>=1 then we reverse all elements in the array. Algorithm Revarray(A, n, p) /* A is an integer Array, n is the size of an array and every sub-array of size p starting ... Read More

Python program to communicate between parent and child process using the pipe.

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

741 Views

Using fork is the easiest way to create child process.fork () is part of the os standard Python library. Here, we solve this task by using of pipe(). For passing information from one process to another pipe() is used. For two way communication two pipes can be use, one for each direction because pipe() is unidirectional. Algorithm Step 1: file descriptors r, w for reading and writing. Step 2: Create a process using the fork. Step 3: if process id is 0 then create a child process. Step 4: else create parent process. Example Code import os ... Read More

Python program to check the validity of a Password?

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

2K+ Views

Here given a password, our task is to check that this Password is valid or not. Here we use re module that provide regular expression and re.search() is used for checking the validation of alphabets, digits or special characters. Algorithm Step 1: first we take an alphanumeric string as a password. Step 2: first check that this string should minimum 8 characters. Step 3: the alphabets must be between a-z. Step 4: At least one alphabet should be in Uppercase A-Z. Step 5: At least 1 number or digit between 0-9. Step 6: At least 1 character from [_ ... Read More

Python program to iterate over multiple lists simultaneously?

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

227 Views

Here we use .zip() for iterative over multiple lists simultaneously.zip() takes n number of iterables and returns list of tuples. i-th element of the tuple is created using the ith element from each of the iterables. Example L1=[1, 2, 3, 4] L2=[‘aa’, ’bb’, ’cc’, ’dd’] L=zip(L1, L2) Output [(1, ’aa’), (2, ’bb’), (3, ’cc’), (4, ’dd’)] Algorithm Step 1: first create 3 user input list. Step 2 : use .zip() function. Step 3: print tuples. Example code # To iterate over 3 lists using zip function importitertools A=list() B=list() C=list() n = int(input("How many you ... Read More

Get emotions of images using Microsoft emotion API in Python?

Samual Sam
Updated on 23-Jun-2020 15:44:05

98 Views

Every human being have emotions just like happy, sad, neutral, surprise, sorrow etc., if we create the emotions of images like happy, sad, neutral, surprise, etc. in Python. We can use Microsoft emotion API for any development purpose.We can easily elaborate all these emotions using Microsoft emotion API's.Example Codeimport http.client, urllib.request import urllib.parse, urllib.error import base64, sys import simplejson as json # replace with subscription_key # you obtained after registration subscription_key = '23d39244dbe55173214b56ab45d56cla' headers = {    # Request for headers. And also replace the placeholder key with    # our subscription key.    'Content-Type': 'application/json',    'Ocp-Apim-Subscription-Key': ... Read More

Segregate 0’s and 1’s in an array list using Python?

Sarika Singh
Updated on 19-Dec-2022 12:06:22

1K+ Views

The elements in the contiguous memory address are contained in the linear data structure known as an array. At these places, it primarily groups components of the same data type. Given an array of integers. The array is to be divided into two halves, 0s and 1s, according to the article "Segregate 0s and 1s in an array." The array should have all the 0’s on the left and all the 1’s on the right. Input-Output Scenario Let’s consider an input and its output scenarios to segregate 0’s and 1’s in an array list - Input: [0, 1, ... Read More

Python program to check if there are K consecutive 1’s in a binary number?

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

231 Views

First we take a user input string with the combination of 1’s and 0’s.then create a new string with 1’s, then check if there is any p number of consecutive 1’s is present or not. If present then display FOUND otherwise NOTFOUND. Example Binary number ::1111001111 Enter consecutive 1’s :3 Consecutive 1's is Found Algorithm Step 1: input a string with the combination of 1’s, it’s stored in the variable X and 0’s and p is the consecutive 1’s in a binary number. Step 2: form a new string of p 1’s. newstring=”1”*p Step ... Read More

Python program to split and join a string?

Sarika Singh
Updated on 23-Nov-2022 08:08:52

8K+ Views

We'll learn how to split and join a string in Python in this article. Python defines strings as a collection of characters enclosed in one, two, or three quotations. When a string is split, it is divided into smaller strings using a specific delimiter. A set of one or more characters used to define a boundary is known as a delimiter. Anything could serve as a delimiter. The comma (, ), semicolon (;), tab (t), space (), and pipe (|) are the most widely used delimiters. Everywhere the specified delimiter appears in a given string, we must split it, and ... Read More

Python program to multiply all numbers in the list?

Sarika Singh
Updated on 23-Nov-2022 08:03:08

20K+ Views

You will understand how to multiply every number in a list in Python in this article using various methods. A list is an ordered collection of values that are enclosed in square brackets. List contains values known as items that can be retrieved by their unique index. We'll create a function that multiplies each value in the list and outputs the result. The result of multiplying all the values is a single thing. For instance, the result will be 36 for the list [3, 2, 6]. We will go over the various methods for calculating the sum of all the ... Read More

Python program to Remove and print every third from list until it becomes empty?

Sarika Singh
Updated on 23-Nov-2022 08:05:38

1K+ Views

In this article, we will learn how to remove and print every third element or item from the list until it becomes empty using Python Program. First we create a list, the index of the starting address is 0 and the position of the first third element is 2 and need to traverse till the list becomes empty and another important work to do every time we have to find the index of the next third element and print the value and after that reduce the length of the list. Input-Output Scenario Following is the input and its output scenario ... Read More

Advertisements