Featured Post

Python map() and lambda() Use Cases and Examples

Image
 In Python, map() and lambda functions are often used together for functional programming. Here are some examples to illustrate how they work. Python map and lambda top use cases 1. Using map() with lambda The map() function applies a given function to all items in an iterable (like a list) and returns a map object (which can be converted to a list). Example: Doubling Numbers numbers = [ 1 , 2 , 3 , 4 , 5 ] doubled = list ( map ( lambda x: x * 2 , numbers)) print (doubled) # Output: [2, 4, 6, 8, 10] 2. Using map() to Convert Data Types Example: Converting Strings to Integers string_numbers = [ "1" , "2" , "3" , "4" , "5" ] integers = list ( map ( lambda x: int (x), string_numbers)) print (integers) # Output: [1, 2, 3, 4, 5] 3. Using map() with Multiple Iterables You can also use map() with more than one iterable. The lambda function can take multiple arguments. Example: Adding Two Lists Element-wise list1 = [ 1 , 2 , 3 ]

Here is Sample Logic to get Random numbers in Bash

How to generate random number



Here's a bash script to generate a random number. You can use this logic to generate a random number, and it is useful for AWS engineers.

Random number


Script - Here's sample logic to get a random number



RANDOM=$$ # Set the seed to the PID of the script
UPPER_LIMIT=$1
RANDOM_NUMBER=$(($RANDOM % $UPPER_LIMIT + 1))
echo "$RANDOM_NUMBER"




If you select UPPER_LIMIT as 100, then the result would be a pseudo-random number between 1 and 100.

Her is the output after executing the script





Related posts

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Python placeholder '_' Perfect Way to Use it