Found 10476 Articles for Python

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

278 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

224 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

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

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

601 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

892 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

311 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

196 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

How to use Boto3 to paginate through security configuration present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:19:41

228 Views

In this article, we will see how to paginate through security configuration present in AWS Glue.ExampleProblem Statement: Use boto3 library in Python to paginate through security configuration 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.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, ... Read More

How to use Boto3 to paginate through all jobs present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:18:56

684 Views

In this article, we will see how to paginate through all jobs present in AWS Glue.ExampleProblem Statement: Use boto3 library in Python to paginate through jobs 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.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 ... Read More

How to use Boto3 to paginate through the job runs of a job present in AWS Glue

Ashish Anand
Updated on 15-Apr-2021 13:18:37

503 Views

In this article, we will see how to paginate through all the job runs of a job present in AWS Glue.ExampleProblem Statement: Use boto3 library in Python to paginate through job runs of a job 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 job_name is 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 ... Read More

Remove Tuples from the List having every element as None in Python

AmitDiwan
Updated on 15-Apr-2021 13:15:53

371 Views

When it is required to remove tuples from a list of tuples where a ‘None’ element is present, a list comprehension can be used.Below is a demonstration of the same −Example Live Demomy_list = [(2, None, 12), (None, None, None), (23, 64), (121, 13), (None, ), (None, 45, 6)] print("The list is : ") print(my_list) my_result = [sub for sub in my_list if not all(elem == None for elem in sub)] print("The None tuples have been removed, the result is : " ) print(my_result)OutputThe list is : [(2, None, 12), (None, None, None), (23, 64), (121, 13), (None, ... Read More

Advertisements