Server Side Programming Articles - Page 1953 of 2650

Windows registry access using Python (winreg)

Pradeep Elance
Updated on 07-Jan-2020 06:53:49

6K+ Views

As a versatile language and also availability of very large number of user supported modules, we find that python is also good at OS level programming. In this article we will see how python can access the registry of a windows operating system.We need to import the module named winreg into the python environment.In the below example we use the winreg module to first connect to the registry using the ConnectRegistry function and then access the registry using OpenKey function. Finally we design a for loop to print the result of the keys accessed.Exampleimport winreg #connecting to key in registry ... Read More

Python - Filter the negative values from given dictionary

Pradeep Elance
Updated on 07-Jan-2020 06:48:05

541 Views

As part of data analysis, we will come across scenarios to remove the negative values form a dictionary. For this we have to loop through each of the elements in the dictionary and use a condition to check the value. Below two approaches can be implemented to achieve this.Using for loopW simply loop through the elements of the list using a for loop. In every iteration we use the items function to compare the value of the element with the 0 for checking negative value.Example Live Demodict_1 = {'x':10, 'y':20, 'z':-30, 'p':-0.5, 'q':50} print ("Given Dictionary :", str(dict_1)) final_res_1 ... Read More

Python - Filter even values from a list

Pradeep Elance
Updated on 07-Jan-2020 06:46:30

1K+ Views

As part of data analysis require to filter out values from a list meeting certain criteria. In this article we'll see how to filter out only the even values from a list.We have to go through each element of the list and divide it with 2 to check for the remainder. If the remainder is zero then we consider it as an even number. After fetching these even numbers from a list we will put a condition to create a new list which excludes this even numbers. That new list is the result of the filtering condition we applied.Using for ... Read More

Multiplication of two Matrices in Single line using Numpy in Python

Pradeep Elance
Updated on 07-Jan-2020 06:41:16

743 Views

Matrix multiplication is a lengthy process where each element from each row and column of the matrixes are to be multiplied and added in a certain way. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result matrix has the number of rows of the first and the number of columns of the second matrix.For smaller matrices we may design nested for loops and find the result. For bigger matrices we need some built in functionality in python to tackle this. We will see both ... Read More

All possible permutations of N lists in Python

Pradeep Elance
Updated on 07-Jan-2020 06:34:45

1K+ Views

If we have two lists and we need to combine each element of the first element with each element of the second list, then we have the below approaches.Using For LoopIn this straight forward approach we create a list of lists containing the permutation of elements from each list. we design a for loop within another for loop. The inner for loop refers to the second list and Outer follow refers to the first list.Example Live DemoA = [5, 8] B = [10, 15, 20] print ("The given lists : ", A, B) permutations = [[m, n] for m in ... Read More

Add leading Zeros to Python string

Pradeep Elance
Updated on 18-Feb-2020 11:22:50

649 Views

We may sometimes need to append zeros as string to various data elements in python. There may the reason for formatting and nice representation or there may be the reason for some calculations where these values will act as input. Below are the methods which we will use for this purpose.Using format()Here we take a DataFrame and apply the format function to the column wher we need to append the zeros as strings. The lambda method is used to apply the function repeatedly.Example Live Demoimport pandas as pd string = {'Column' : ['HOPE', 'FOR', 'THE', 'BEST']} dataframe=pd.DataFrame(string) print("given column is ") ... Read More

Convert all lowercase characters to uppercase whose ASCII value is co-prime with k in C++

Ayush Gupta
Updated on 06-Jan-2020 12:24:57

141 Views

In this tutorial, we will be discussing a program to convert all lowercase characters to uppercase whose ASCII value is co-prime with k.For this we will be provided with a string and an integer value k. Our task is to traverse through the given string and change to uppercase all those characters whose ASCII value is co-prime with the given integer k.Example Live Demo#include using namespace std; //modifying the given string void convert_string(string s, int k){    int l = s.length();    for (int i = 0; i < l; i++) {       int ascii = (int)s[i];   ... Read More

Convert a tree to forest of even nodes in C++

Ayush Gupta
Updated on 06-Jan-2020 12:14:35

247 Views

In this tutorial, we will be discussing a program to convert a tree to a forest of even nodes.For this we will be provided with a binary tree of say N nodes. Our task is to calculate the maximum number of edges that can be removed to get forest of even nodes.Example Live Demo#include #define N 12 using namespace std; //returning the number of nodes of subtree //having the root node int depth_search(vector tree[N], int visit[N], int *ans, int node){    int num = 0, temp = 0;    //marking nodes as visited    visit[node] = 1;    for (int i ... Read More

Convert a string to hexadecimal ASCII values in C++

Ayush Gupta
Updated on 06-Jan-2020 12:10:54

2K+ Views

In this tutorial, we will be discussing a program to convert a string to hexadecimal ASCII values.For this we will be provided with a string of characters. Our task is to print that particular given string into its hexadecimal equivalent.Example Live Demo#include #include //converting string to hexadecimal void convert_hexa(char* input, char* output){    int loop=0;    int i=0;    while(input[loop] != '\0'){       sprintf((char*)(output+i), "%02X", input[loop]);       loop+=1;       i+=2;    }    //marking the end of the string    output[i++] = '\0'; } int main(){    char ascii_str[] = "tutorials point";   ... Read More

Convert a String into a square matrix grid of characters in C++

Ayush Gupta
Updated on 06-Jan-2020 12:06:36

392 Views

In this tutorial, we will be discussing a program to convert a string into a square matrix grid of characters.For this we will be provided with a string of characters. Our task is to print that particular string in the format of a matrix grid having a certain number of rows and columns.Example Live Demo#include using namespace std; //converting the string in grid format void convert_grid(string str){    int l = str.length();    int k = 0, row, column;    row = floor(sqrt(l));    column = ceil(sqrt(l));    if (row * column < l)       row = column; ... Read More

Advertisements