Found 26504 Articles for Server Side Programming

How to use Boto3 to paginate through table versions of a table present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:25:44

275 Views

Problem Statement: Use boto3 library in Python to paginate through table versions of a table from AWS Glue Data Catalog that is created in your accountApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: max_items, page_size and starting_token are the optional parameters for this function, while database_name and table_name are required.max_items denote the total number of records to return. If the number of available records > max_items then a NextToken will be provided in the response to resume pagination.page_size denotes the size of each page.starting_token helps to paginate, and it uses NextToken from a ... Read More

Python Program to Check whether a Singly Linked List is a Palindrome

AmitDiwan
Updated on 15-Apr-2021 13:27:17

222 Views

When it is required to check if a singly linked list is a palindrome or not, methods to add an element, get the previous node and to check if a palindrome is formed are defined.Below is a demonstration of the same −Example Live Democlass Node:    def __init__(self, data):       self.data = data       self.next = None class LinkedList_struct:    def __init__(self):       self.head = None       self.last_node = None    def add_elements(self, data):       if self.last_node is None:          self.head = Node(data)       ... Read More

Difference between import tkinter as tk and from tkinter import

Dev Prakash Sharma
Updated on 15-Apr-2021 13:23:42

5K+ Views

In order to work with tkinter applications and widgets, we have to import the tkinter library in the environment. There are multiple ways to import the tkinter library in the notebook.Using from tkinter import *Using import tkinter as tkThe first method to import the tkinter library is the most common, as it comes with all the inbuilt methods or functions. In the general sense, we don’t have to explicitly override the method for the widgets. In this way, we can create the object of widgets just by using the widget constructor. It comes with all the modules defined in tkinter.However, ... Read More

Difference between "fill" and "expand" options for tkinter pack method

Dev Prakash Sharma
Updated on 15-Apr-2021 13:19:17

4K+ Views

Tkinter Pack Manager acts based on using the extra space within the parent widget. While packing a widget, we can specify whether the widget should shrink or fill in the entire screen. In order to enable the widget to grow in the entire window, we can use the 'fill' property. It helps to fill the widget in the screen by adding “x” as horizontal, “y” as vertical or “BOTH”.Whenever we use expand(boolean) property, then we are generally resizing the widget size to expand in its available space. It takes boolean values as true or false. When the expand property is ... Read More

Python program to find Tuples with positive elements in List of tuples

AmitDiwan
Updated on 15-Apr-2021 13:20:44

598 Views

When it is required to find tuples that have position elements from a list of tuples, list comprehension can be used.Below is a demonstration of the same −Example Live Demomy_list = [(56, 43), (-31, 21, 23), (51, -65, 26), (24, 56)] print("The list is : ") print(my_list) my_result = [sub for sub in my_list if all(elem >= 0 for elem in sub)] print("The positive elements are : ") print(my_result)OutputThe list is : [(56, 43), (-31, 21, 23), (51, -65, 26), (24, 56)] The positive elements are : [(56, 43), (24, 56)]ExplanationA list of tuples is defined, and is ... Read More

Python program to find tuples which have all elements divisible by K from a list of tuples

AmitDiwan
Updated on 15-Apr-2021 13:20:04

889 Views

When it is required to find tuples that have elements that are divisible by a specific element ‘K’, the list comprehension can be used.Below is a demonstration of the same −Example Live Demomy_list = [(45, 90, 135), (71, 92, 26), (2, 67, 98)] print("The list is : ") print(my_list) K = 45 print("The value of K has been initialized to ") print(K) my_result = [sub for sub in my_list if all(ele % K == 0 for ele in sub)] print("Elements divisible by K are : " + str(my_result))OutputThe list is : [(45, 90, 135), (71, 92, 26), (2, ... Read More

Python program to Sort Tuples by their Maximum element

AmitDiwan
Updated on 15-Apr-2021 13:19:45

306 Views

When it is required to sort the tuples based on the maximum element in it, a method is defined that uses the ‘max’ method to return the highest element.Next the ‘sort’ method can be used to sort the list based on the previously defined function.Below is a demonstration of the same −Example Live Demodef get_max_value(my_val):    return max(my_val) my_list = [(4, 6, 8, 1), (13, 21, 42, 56), (7, 1, 9, 0), (1, 2)] print(“The list is : “) print(my_list) my_list.sort(key = get_max_value, reverse = True) print(“The sorted tuples are : “) print(my_list)OutputThe list is : [(4, 6, ... Read More

Consecutive Nth column Difference in Tuple List using Python

AmitDiwan
Updated on 15-Apr-2021 13:19:27

195 Views

When it is required to find the consecutive column difference in a list of tuple, it can be iterated over, and the ‘abs’ method and the ‘append’ method can be used.The ‘abs’ method returns the absolute or positive value, and the append adds elements to a list.Below is a demonstration of the same −Example Live Demomy_list = [(67, 89, 32), (11, 23, 44), (65, 75, 88)] print("The list is : ") print(my_list) print("The value of k has been initialized") K = 1 my_result = [] for idx in range(0, len(my_list) - 1):    my_result.append(abs(my_list[idx][K] - my_list[idx + 1][K])) ... Read More

Creating a popup message box with an Entry field in tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:17:44

7K+ Views

Tkinter Popup are toplevel window interfaces that wrap up the widget and the element with the main window. It can be embedded in any main window using a handler like Button Widget. Popup can be created using the Toplevel(root) constructor.ExampleIn this example, we will create a simple application containing a Label widget and a button to open the popup message box which contains an Entry field. Once the popup is opened, it can have the functionality to go back to the main window.#Import the required library from tkinter import* #Create an instance of tkinter frame win= Tk() #Define geometry of ... Read More

Change the focus from one Text widget to another in Tkinter

Dev Prakash Sharma
Updated on 15-Apr-2021 13:13:45

1K+ Views

In various applications, tkinter widgets are required to be focused to make them active. Widgets can also grab focus and prevent the other events outside the bounds. To manage and give focus to a particular widget, we generally use the focus_set() method. It focuses the widget and makes them active until the termination of the program.ExampleIn the following example, we have created two text widgets and we will change the focus from one text widget to another text widget simultaneously using a button widget. Thus, changing the focus is easy by defining two methods which can be handled through the ... Read More

Advertisements