Python Program to Print the Pattern G

AmitDiwan
Updated on 15-Apr-2021 13:05:23

586 Views

When it is required to print the pattern of the letter ‘G’ using ‘*’, a method can be defined, and nested loop can be used to iterate through the numbers and print ‘*” to form a ‘G’ pattern.Below is a demonstration of the same −Exampledef display_pattern(my_line):    my_pattern=""    for i in range(0, my_line):       for j in range(0, my_line):          if ((j == 1 and I != 0 and I != my_line-1) or ((I == 0 or I == my_line-1) and j > 1 and j < my_line-2) or (I == ((my_line-1)/2) and j ... Read More

Display Fibonacci Sequence Using Recursion in Python

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

394 Views

When it is required to print the fibonacci sequence using the method of recursion, a method can be declared that calls the same method again and again until a base value is reached.Below is a demonstration of the same −Example Live Demodef fibonacci_recursion(my_val):    if my_val

Stop a Crawler in AWS Glue Data Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:02:17

260 Views

In this article, we will see how a user can stop a crawler present in an AWS Glue Data Catalog.ExampleProblem Statement: Use boto3 library in Python to stop a crawler.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: crawler_name is the parameter in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the stop_crawler function and pass the parameter crawler_name ... Read More

Stop a Workflow in AWS Glue Data Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:01:57

531 Views

In this article, we will see how a user can stop a workflow present in an AWS account.ExampleProblem Statement: Use boto3 library in Python to stop a workflow.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name and run_id are the required parameters in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the stop_workflow_run function and pass the parameter ... Read More

Use Boto3 to Start a Workflow in AWS Glue Data Catalog

Ashish Anand
Updated on 15-Apr-2021 13:01:39

753 Views

In this article, we will see how a user can start a workflow in AWS Glue Data Catlog.ExampleProblem Statement: Use boto3 library in Python to start a workflow.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: workflow_name is parameter in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use start_workflow_run function and pass the parameter workflow_name as Name.Step 6: It returns ... Read More

Stop a Trigger in AWS Glue Data Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:01:12

392 Views

In this article, we will see how a user can stop a trigger in AWS Glue Data Catalog.ExampleProblem Statement: Use boto3 library in Python to stop a trigger.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: trigger_name is parameter in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the stop_trigger function and pass the parameter trigger_name as Name.Step 6: ... Read More

Start a Trigger in AWS Glue Data Catalog Using Boto3

Ashish Anand
Updated on 15-Apr-2021 13:00:51

566 Views

In this article, we will see how a user can start a trigger in AWS Glue Data Catalog.ExampleProblem Statement: Use boto3 library in Python to start a trigger.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: trigger_name is the parameter in this function.Step 3: Create an AWS session using boto3 lib. Make sure region_name is mentioned in the default profile. If it is not mentioned, then explicitly pass the region_name while creating the session.Step 4: Create an AWS client for glue.Step 5: Now use the start_trigger function and pass the parameter trigger_name as Name.Step ... Read More

Unique Keys Count for Value in Tuple List in Python

AmitDiwan
Updated on 15-Apr-2021 12:58:40

169 Views

When it is required to get the count of unique keys for values in a list of tuple, it can be iterated over and the respective counts can be determined.Below is a demonstration of the same −Example Live Demoimport collections my_result = collections.defaultdict(int) my_list = [[('Hello', 'Hey')], [('Jane', 'Will')], [('William', 'John')], [('Hello', 'Hey')], [('z', 'q')]] print("The list of list is :") print(my_list) for elem in my_list:    my_result[elem[0]] += 1 print("The result is : ") print(my_result)OutputThe list of list is : [[('Hello', 'Hey')], [('Jane', 'Will')], [('William', 'John')], [('Hello', 'Hey')], [('z', 'q')]] The result is : defaultdict(, {('Hello', 'Hey'): 2, ('Jane', ... Read More

Count Bidirectional Tuple Pairs in Python

AmitDiwan
Updated on 15-Apr-2021 12:58:16

204 Views

When it is required to count the number of bidirectional tuple pairs in a list of tuples, the list can be iterated over using nested loops, and the ‘AND’ operation is performed on the first element and result of equality between first and second element.Below is a demonstration of the same −Example Live Demomy_list = [(45, 67), (11, 23), (67, 45), (23, 11), (0, 9), (67, 45)] print("The list is : ") print(my_list) my_result = 0 for idx in range(0, len(my_list)):    for iidx in range(idx + 1, len(my_list)):       if my_list[iidx][0] == my_list[idx][1] and my_list[idx][1] == ... Read More

Sum of All Nodes in a Tree using Python

AmitDiwan
Updated on 15-Apr-2021 12:57:57

423 Views

When it is required to get the sum of all the nodes in a Tree, a ‘Tree_structure’ class is created, methods to set a root value, and to add other values are defined. It also has a method to determine the sum of all elements of a Tree structure. Various options are given that the user can select. Based on the user’s choice, the operation is performed on the Tree elements.Below is a demonstration of the same −Example Live Democlass Tree_structure:    def __init__(self, data=None):       self.key = data       self.children = []    def set_root(self, ... Read More

Advertisements