Print Elements of an Array in Reverse Order in Python

AmitDiwan
Updated on 16-Apr-2021 11:57:09

814 Views

When it is required to print the elements of an array in reverse order, the list can be iterated over from the end.Below is a demonstration of the same −Example Live Demomy_list = [21, 32, 43, 54, 75] print("The list is : ") for i in range(0, len(my_list)):    print(my_list[i]) print("The list after reversal is : ") for i in range(len(my_list)-1, -1, -1):    print(my_list[i])OutputThe list is : 21 32 43 54 75 The list after reversal is : 75 54 43 32 21ExplanationA list is defined, and is displayed on the console.The list is iterated over, and displayed.It is reversed ... Read More

Print Duplicate Elements of an Array in Python

AmitDiwan
Updated on 16-Apr-2021 11:56:51

2K+ Views

When it is required to print the duplicate elements of an array, the list elements are iterated over, and a nested loop is used.Below is a demonstration of the same −Example Live Demomy_list = [1, 2, 5, 6, 8, 9, 3, 4, 8, 9, 1, 8] print("The list is :") print(my_list) print("The duplicate elements in the list are : ") for i in range(0, len(my_list)):    for j in range(i+1, len(my_list)):       if(my_list[i] == my_list[j]):          print(my_list[j])OutputThe list is : [1, 2, 5, 6, 8, 9, 3, 4, 8, 9, 1, 8] The duplicate elements in ... Read More

Python Program to Left Rotate the Elements of an Array

AmitDiwan
Updated on 16-Apr-2021 11:56:27

2K+ Views

When it is required to left rotate the elements of an array, the array can be iterated over, and depending on the number of left rotations, the index can be incremented that many times.Below is a demonstration of the same −Example Live Demomy_list = [11, 12, 23, 34, 65] n = 3 print("The list is : ") for i in range(0, len(my_list)):    print(my_list[i]) for i in range(0, n):    first_elem = my_list[0]    for j in range(0, len(my_list)-1):       my_list[j] = my_list[j+1]    my_list[len(my_list)-1] = first_elem print() print("Array after left rotating is ... Read More

Find Function Pagination in AWS Secret Manager using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:57:29

564 Views

Problem Statement: Use boto3 library in Python to find out whether a function can paginate or not in AWS secret.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: secret_function is the required 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 secretmanager.Step 5: Now use the can_paginate function and pass the parameter secret_function.Step 6: It returns True if the function can paginate; ... Read More

Remove Tags in Specified AWS Secrets Using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:56:53

347 Views

Problem Statement: Use boto3 library in Python to remove tags in AWS secret.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: secret_location and tags_list are the required parameters in this function. tags_list should be the list of keys to be untaged.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 secretmanager.Step 5: Now use the untag_resource function and pass the parameter secret_location as SecretId and tags_list ... Read More

Add Tags to Specified AWS Secrets Using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:55:55

857 Views

Problem Statement: Use boto3 library in Python to add tags in AWS secret.Approach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: secret_location and tags_dict are the required parameters in this function. tags_dict should be as {“key”:”value”, ..}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 secretmanager.Step 5: Now use tag_resource function and pass the parameter secret_location as SecretId and tags_dict as Tags.Step 6: It returns ... Read More

Store a New Secret in AWS Secrets Manager using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:55:36

263 Views

Problem Statement: Use boto3 library in Python to store a new secret in a specific location in AWS Secret ManagerApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: secret_stored_location and secret_key_pair are the required parameters. Make sure secret_key_pair is written as string, not as dict.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 secretmanager.Step 5: Call put_secret_value and pass the secret_stored_location as SecretId and secret_key_pair ... Read More

Get List of All Secrets in AWS Secret Manager using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:55:15

2K+ Views

Problem Statement: Use boto3 library in Python to get a list of all secrets in AWS Secret ManagerApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters here.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 secretmanager.Step 5: Call list_secrets function to retrieve all secrets.Step 6: It returns the metadata of all secrets.Step 7: Handle the generic exception if something went wrong ... Read More

Difference Between Stack and Heap

AmitDiwan
Updated on 16-Apr-2021 07:54:14

2K+ Views

In this post, we will understand the difference between Stack and HeapStackIt is a linear data structure.Memory is allocated in a contiguous (continuous) block.The memory for a stack is allocated and deallocated automatically using the instructions of the compiler.It costs less to build and maintain a stack.It is easy to implement.It is fixed in size; hence it is not flexible.Its only disadvantage is the shortage of memory, since it is fixed in size.If all the blocks are not occupied, memory gets wasted too.It takes less time to access the elements of a stack.It has an excellent locality of reference.HeapIt is ... Read More

Generate Random Password in AWS Secret Manager Using Boto3

Ashish Anand
Updated on 16-Apr-2021 07:50:42

639 Views

Problem Statement: Use boto3 library in Python to generate a random password in AWS Secret ManagerApproach/Algorithm to solve this problemStep 1: Import boto3 and botocore exceptions to handle exceptions.Step 2: There are no parameters here.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 secretmanager.Step 5: Call get_random_password and pass the parameter as per the desired complexity.Step 6: It returns a random password.Step 7: Handle the generic exception if something went wrong ... Read More

Advertisements