The Dataframe in pandas can be created using various options. One of the option is to take a dictionary and convert it to a Dataframe. In this article we will see how to take three lists of equal length and convert them to a pandas dataframe using a python dictionary.Uisng Lists and DictionaryIn this approach we have the lists declared individually. Then each of them is used as a value for the appropriate key inside a dictionary definition. Finally the pandas method called pd.Dataframe is applied to the dictionary.Example Live Demoimport pandas as pd # Lists for Exam schedule Days ... Read More
Python Tkinter can be used to create all kinds of GUI programs for the web and desktop. In this article we will see how to create a digital clock displaying hour, minute and seconds live.We use the time module to import the method strftime which displays the time in Hour, minute and seconds format. We create a canvas to hold these values. We refresh the values of strftime after every 200 milli seconds. We define a recursive function to achieve this.Exampleimport time from tkinter import * canvas = Tk() canvas.title("Digital Clock") canvas.geometry("350x200") canvas.resizable(1, 1) label = Label(canvas, font=("Courier", 30, 'bold'), ... Read More
The progressbar is a common GUI element which is used to show the progress of certain task. In tis article we will see how to create a progressbar using the Python tkinter GUI library.In the below program we have imported the progressbar sub-module of tkinter.ttk module. Then used the style object to create the style options and supply the value for the length of the button as well as value of the progress.Exampleimport tkinter as tk from tkinter.ttk import Progressbar from tkinter import ttk canv = tk.Tk() canv.title("Tkinter Progressbar") canv.geometry('250x100') style = ttk.Style() style.theme_use('default') style.configure("grey.Horizontal.TProgressbar", background='blue') bar = Progressbar(canv, length=180, ... Read More
Every programming language has a feature to create scripts and run them from the terminal or being called by other programs. When running such scripts we often need to pass on arguments needed by the script for various functions to be executed inside the script. In this article we will see what are the various ways to pass arguments into a python script.Using sys.argvThis is a inbuilt module sys.argv can process arguments that are passed on with the script. By default the first argument which is considered at sys.argv[0] is the file name. the rest of the arguments are indexed ... Read More
Tkinter has great support for creating the GUI programs based on python. It offers different ways of styling a button on the Tkinter canvas based on its font, size, colour etc. In this article we will see how to apply style to specific buttons or all buttons in general on the canvas.Applying to Specific ButtonsLets consider the case when we have two buttons in the canvas and we want to apply some styling only to the first button. We use the W.TButton as part of the configuration along with the font and the foreground colour.Examplefrom tkinter import * from tkinter.ttk ... Read More
Suppose we have a balanced binary search tree, we have to create a function named is_valid_triplet() that returns true when there exist a triplet in given BST whose sum equals to 0, otherwise returns false. Design the method by following these constraints −expected time complexity is O(n^2)O(logn) extra space can be used.So, if the input is likethen the output will be True, as triplet is [-15, 7, 8]To solve this, we will follow these steps −Define a function bst_to_doubli_list(), this will take root, head, tail, if root is same as NULL, then −returnif left of root is not null, then ... Read More
Suppose we have a list of tickets represented by pairs of departure and arrival airports like [from, to], we have to find the itinerary in order. All of the tickets belong to a man who departs from Chennai. So, the itinerary must begin with Chennai.So if the input is like [["Mumbai", " Kolkata"], ["Chennai ", " Mumbai"], ["Delhi", "Bangalore"], ["Kolkata", " Delhi"]], then the output will be ["Chennai", " Mumbai", " Kolkata", " Delhi", "Bangalore"].To solve this, we will follow these steps −Define array ret and a map called graph.Define a method called visit. This will take airport name as ... Read More
Suppose we have a list of N jobs where each job has three parameters. 1. Start Time 2. Finish Time 3. Profit We have to find a subset of jobs associated with maximum profit so that no two jobs in the subset overlap.So, if the input is like N = 4 and J = {{2, 3, 55},{4, 6, 25},{7, 20, 150},{3, 150, 250}} , then the output will be [(2, 3, 55),(3, 150, 250)] and optimal profit 305To solve this, we will follow these steps −Define a function find_no_conflict(), this will take an array jobs, index,left := 0, right := index - 1while left
Suppose we have a binary search tree and a value K as input, we have to find K-th smallest element in the tree.So, if the input is likek = 3, then the output will be 15.To solve this, we will follow these steps −Define a function find_kth_smallest(), this will take root, count, k, if root is NULL, then −return NULLleft = find_kth_smallest(left of root, count, k)if left is not NULL, then −return left(increase count by 1)if count is same as k, then −return rootreturn find_kth_smallest(right of root, count, k)From the main method, do the following −count := 0res = find_kth_smallest(root, ... Read More
Suppose we have a RAM and that RAM is organized in blocks. there are multiple processes running on the system. We have to keep in mind that every process gets following information, (Thread T, Memory Block M, time t, R/W) This indicates the thread T was implementing memory block M at given time t and operation could be either read(R) or write(W).The following case is indicating whether it is memory conflict or not −More than one read operations at the same location are not the reason of conflict.When writing operation is being performed between x+5 to x-5 to location of ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP