
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
Found 33676 Articles for Programming

9K+ Views
Problem.You need to compare files in Python.Solution..The filecmp module in python can be used to compare files and directories. 1.cmp(file1, file2[, shallow])filecmp Compares the files file1 and file2 and returns True if identical, False if not. By default, files that have identical attributes as returned by os.stat() are considered to be equal. If shallow is not provided (or is True), files that have the same stat signature are considered equal.cmpfiles(dir1, dir2, common[, shallow])Compares the contents of the files contained in the list common in the two directories dir1 and dir2. cmpfiles returns a tuple containing three lists - match, mismatch, ... Read More

158 Views
IntroductionIn a real world corporate business setting, most data may not be stored in text or Excel files. SQL-based relational databases such as Oracle, SQL Server, PostgreSQL, and MySQL are in wide use, and many alternative databases have become quite popular.The choice of database is usually dependent on the performance, data integrity, and scalability needs of an application.How to do it..In this example we will how to create a sqlite3 database. sqllite is installed by default with python installation and doesn't require any further installations. If you are unsure please try below. We will also import Pandas.Loading data from SQL ... Read More

264 Views
Suppose we have two strings S and T, we have to find all the start indices of S's anagrams in T. The strings consist of lowercase letters only and the length of both strings S and T will not be larger than 20 and 100.So, if the input is like S = "cab" T = "bcabxabc", then the output will be [0, 1, 5, ], as the substrings "bca", "cab" and "abc".To solve this, we will follow these steps:Define a map m, n := size of s, set left := 0, right := 0, counter := size of pdefine an ... Read More

666 Views
IntroductionOne of the most basic and common operations to perform during data analysis is to select rows containing the largest value of some columns within a group. In this post, I will show you how to find the largest of each group within a DataFrame.Problem..Let us understand the task first, assume you are given a movies dataset and requested to list the most popular film of each year based on popularity.How to do it..1.Preparing the data.Well Google is full of datasets. I often use kaggle.com to get the datasets I need for my data analysis. Feel free to login to ... Read More

152 Views
Suppose we have two singly linked list L1 and L2, each representing a number with least significant digits first, we have to find the summed linked list.So, if the input is like L1 = [5, 6, 4] L2 = [2, 4, 8], then the output will be [7, 0, 3, 1, ]To solve this, we will follow these steps:carry := 0res := a new node with value 0curr := reswhile L1 is not empty or L2 is not empty or carry is non-zero, dol0_val := value of L1 if L1 is not empty otherwise 0l1_val := value of L2 if ... Read More

1K+ Views
IntroductionOne of the basic limitation of unpacking is that you must know the length of the sequences you are unpacking in advance.How to do it..random_numbers = [0, 1, 5, 9, 17, 12, 7, 10, 3, 2] random_numbers_descending = sorted(random_numbers, reverse=True) print(f"Output *** {random_numbers_descending}")Output*** [17, 12, 10, 9, 7, 5, 3, 2, 1, 0]If I now wanted to find out the largest and second largest from the numbers, we will get an exception "too many values to unpack".print(f"Output *** Getting the largest and second largest") largest, second_largest = random_numbers_descendingOutput*** Getting the largest and second largest--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ... Read More

184 Views
Suppose we have a string s with "x", "y" and "z"s, we have to find the number of subsequences that have i number of "x" characters, followed by j number of "y" characters and followed by k number of "z" characters where i, j, k ≥ 1.So, if the input is like s = "xxyz", then the output will be 3, as we can make two "xyz" and one "xxyz"To solve this, we will follow these steps:n := size of sx := 0, y := 0, z := 0for i in range 0 to n, docount := 0if s[i] is ... Read More

2K+ Views
ProblemYou want to perform various calculations (e.g., minimum value, maximum value, sorting, etc.) on a dictionary of data.Solution.We will create a dictionary with tennis players and their grandslam titles.PlayerTitles = { 'Federer': 20, 'Nadal': 20, 'Djokovic': 17, 'Murray': 3, 'Theim' : 1, 'Zverev': 0 }1.We have a dictionary with player names and the grandslam titles won by each player. Now let us try to find out the player with least number of titles#type(PlayerTitles) print(f"Output *** The minimum value in the dictionary is {min(PlayerTitles)} ")Output*** The minimum value in the dictionary is Djokovic2. This is ... Read More

2K+ Views
IntroductionPandas uses the NumPy NaN (np.nan) object to represent a missing value. This Numpy NaN value has some interesting mathematical properties. For example, it is not equal to itself. However, Python None object evaluates as True when compared to itself.How to do it..Let us see some examples to understand how np.nan behaves.import pandas as pd import numpy as np # Python None Object compared against self. print(f"Output *** {None == None} ")Output*** True# Numpy nan compared against self. print(f"Output *** {np.nan == np.nan} ")Output*** False# Is nan > 10 or 1000 ? print(f"Output *** {np.nan > ... Read More

2K+ Views
ProblemYou want to write a function that accepts any number of input arguments.SolutionThe * argument in python can accepts any number of arguments. We will understand this with an example of finding out the average of any given two or more numbers. In the below example, rest_arg is a tuple of all the extra arguments (in our case numbers) passed. The function treats the arguments as a sequence in performing average calculation.# Sample function to find the average of the given numbers def define_average(first_arg, *rest_arg): average = (first_arg + sum(rest_arg)) / (1 + len(rest_arg)) print(f"Output *** The average for ... Read More