
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 10476 Articles for Python

3K+ Views
Two python dictionaries may contain some common keys between them. In this article we will find how to get the difference in the keys present in two given dictionaries.With setHere we take two dictionaries and apply set function to them. Then we subtract the two sets to get the difference. We do it both ways, by subtracting second dictionary from first and next subtracting first dictionary form second. Those keys which are not common are listed in the result set.Example Live DemodictA = {'1': 'Mon', '2': 'Tue', '3': 'Wed'} print("1st Distionary:", dictA) dictB = {'3': 'Wed', '4': 'Thu', '5':'Fri'} print("1st Distionary:", ... Read More

663 Views
Suppose you are given a list but we want to convert it to dictionary. Dictionary elements hold two values are called key value pair, we will use in case of value. The elements of the list become keys and non will remain a placeholder.With dictThe dict() constructor creates a dictionary in Python. So we will use it to create a dictionary. The fromkeys method is used to create the dictionary elements.Example Live DemolistA = ["Mon", "Tue", "Wed", "Thu", "Fri"] print("Given list: ", listA) res = dict.fromkeys(listA) # New List print("The list of lists:", res)OutputRunning the above code gives us ... Read More

1K+ Views
There may be a situation when we need to convert the elements in the list into a list in itself. In other words, create a list which is nested as its elements are also lists.Using iterationThis is the novel approach in which we take each element of the list and convert it to a format of lists. We use temporary list to achieve this. Finally all these elements which are converted to lists are group together to create the required list of lists.Example Live DemolistA = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] print("Given list:", listA) new_list = [] # Creating ... Read More

237 Views
We know the arithmetic operations between different arrays happens monthly if the arrays are of equal size awesome required specific size. But there are scenarios when we can take erase of unequal size and still apply arithmetic operations on them by enhancing one of the arrays by filling array with smaller ndim prepended with '1' in its shape. So basically broadcasting and array means changing its shape to any required shape.Rules of array BoradcastingArray with smaller ndim than the other is prepended with '1' in its shape.Size in each dimension of the output shape is maximum of the input sizes ... Read More

230 Views
This module provides support for maintaining a list in sorted order without having to sort the list after each insertion of new element. We will focus on two functions namely insort_left and insort_right.insort_leftThis function returns the sorted list after inserting number in the required position, if the element is already present in the list, the element is inserted at the leftmost possible position. This function takes 4 arguments, list which has to be worked with, number to insert, starting position in list to consider, ending position which has to be considered. The default value of the beginning and end position ... Read More

145 Views
When we instantiate a class in Python, all its variables and functions also get inherited to the new instantiated class. But there may be e occasions when we do not want some of the variables of the parent class to be inherited by the child class. In this article, we will explore two ways to do that.Instantiation ExampleIn the below example we show how the variables are instance heated from a given class and how the variables are shared across all the instantiated classes. Live Democlass MyClass: listA= [] # Instantiate Both the classes x = MyClass() y = ... Read More

351 Views
We have a list containing only numbers. We plan to get the average of a set of sequential numbers from the list which keeps rolling from the first number to next number and then to next number and so on.ExampleThe below example simplifies the requirement of finding the average of each 4-length consecutive elements of the list.Given list: [10, 12, 14, 16, 18, 20, 22, 24, 26] Average of every segment of 4 consecutive numbers: [13.0, 15.0, 17.0, 19.0, 21.0, 23.0]With sum and rangeWe use the list comprehension approach to take the sum of the consecutive numbers by ... Read More

1K+ Views
TKinter is a Python module which is used for GUI programming in Python. We create a Canvas and place our UI components with many properties and behaviors in it. In this article, we will see e how to use the ask essay file function to save files created through Python programs into the local drives.We first create a canvas on which we again place a button using the TTK dot button function. Then declare another function that will use the ask fine to define the file type and save the file into location in the local drive.Examplefrom tkinter import * ... Read More

406 Views
Python can help us use excel files directly from the python environment. We can refer to the each cell or a range of cells in excel and apply arithmetic operators on those cells. The results of those operations can also be stored at some cells whose location can be specified by the python program.In the below examples we are performing various arithmetic operations using inbuilt functions of excel. Like sum or average of numbers inside cells. The results are also stored at specific locations. We use the openpyxl module which opens a workbook and marks it active. Then we store ... Read More

2K+ Views
Suppose we want to design and implement a data structure for Least Frequently Used (LFU) cache system. It should support the following operations −get(key) – This will be used to get the value of the key if the key exists in the cache, otherwise return -1.put(key, value) – This will be used to set or insert the value if the key is not already present.When the cache reached its maximum capacity, it should invalidate the least frequently used element before inserting a new element.So, if the LFUCache is initialized with capacity 2 and call these methods cache.put(1, 1); cache.put(2, 2); ... Read More