Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1886 of 2650
287 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.Exampleimport pandas as pd string = {'Column' : ['HOPE', 'FOR', 'THE', 'BEST']} dataframe=pd.DataFrame(string) print("given column is ") print(dataframe) ... Read More
615 Views
Lists can be nested. Which means we have smaller lists as elements inside a bigger list. In this article we solve the challenge of adding the elements of a simple list to the elements of a nested list. If the length of the lists are different then the length of the smaller list becomes the maximum length of the resulting list.Below are the various methods to accomplish this.Using for LoopIn this method, we take the length of the smaller list and loop through the elements of this list adding it to the elements of the bigger list. Here we use ... Read More
2K+ Views
Tkinter, which is the GUI library for python programming has a feature to add images to the GUI buttons. This is useful for users to remember the symbols in the GUI rather than the text in the GUI. In the below Tkinter program we show how we can add an image to a GUI button. The photoimage method from the imageKT module is used. We mention the local path to the image file.Examplefrom tkinter import * from PIL import ImageTk ,Image base = Tk() base.title('Start Button') img=ImageTk.PhotoImage(Image.open ("D:\button.jpg")) lab=Label(image=img) lab.pack() button=Button(base, text='exit', command=base.quit) button.pack() base.mainloop()OutputRunning the above ... Read More
234 Views
In this tutorial, we will be discussing a program to find the number of sub-sequences having product k) { discard_count += power(2, n - i); return; } if (i == n) return; float rem = prefix[n - 1] - prefix[i]; if (sum + a[i] + rem > k) solve(i + 1, n, sum + a[i], k, a, prefix); if (sum + rem > k) solve(i + 1, n, sum, k, a, prefix); } int countSubsequences(const int* arr, ... Read More
156 Views
In this tutorial, we will be discussing a program to find the number of walks from a source to a destination with exactly k edges.For this we will be provided with a graph and the values of source and destination. Our task is to find all the possible paths starting from the source to the destination having exactly k edges.Example Live Demo#include using namespace std; #define V 4 //counting walks using recursion int countwalks(int graph[][V], int u, int v, int k){ if (k == 0 && u == v) return 1; if (k == 1 && graph[u][v]) return 1; if (k
119 Views
In this tutorial, we will be discussing a program to find the number of prefixes of the binary array which are divisible by x.For this we will be provided with binary array and a value x. Our task is to find the number of elements whose prefixes are divisible by given value x.Example Live Demo#include using namespace std; //counting the elements with prefixes //divisible by x int count_divx(int arr[], int n, int x){ int number = 0; int count = 0; for (int i = 0; i < n; i++) { number = number ... Read More
237 Views
In this tutorial, we will be discussing a program to find the number of quadruples from four arrays such that their XOR equals to x.For this we will be provided with four arrays and a value x. Our task is to count all the quadruples whose XOR is equal to the given value x.Example Live Demo#include using namespace std; //counting quadruples with XOR equal to x int count_quad(int a[], int b[], int c[], int d[], int x, int n){ int count = 0; for (int i = 0 ; i < n ; i++) for (int ... Read More
192 Views
In this tutorial, we will be discussing a program to find the number of prime length palindromic strings.For this we will be provided with a string. Our task is to count all the sub strings which are palindromes and have prime lengths.Example Live Demo#include using namespace std; //checking for a palindrome bool if_palin(string str, int i, int j){ while (i < j) { if (str[i] != str[j]) return false; i++; j--; } return true; } //counting palindrome with prime length int count_prime(string str, int ... Read More
263 Views
In this tutorial, we will be discussing a program to find the number of sub-arrays having sum divisible by k.For this we will be provided with an array and a value k. Our task is to find the number of sub arrays that are having their sum as equal to the given value k.Example Live Demo#include using namespace std; //counting subarrays with k sum int count_subarray(int arr[], int n, int k){ int mod[k]; memset(mod, 0, sizeof(mod)); int cumSum = 0; for (int i = 0; i < n; i++) { cumSum += arr[i]; ... Read More
255 Views
In this tutorial, we will be discussing a program to find the number of all sorted rows in a matrix.For this we will be provided with m*n matrix. Our task is to count all the rows in the given matrix that are sorted either in ascending or descending order.Example Live Demo#include #define MAX 100 using namespace std; //counting sorted rows int count_srows(int mat[][MAX], int r, int c){ int result = 0; for (int i=0; i