Created
February 11, 2023 19:19
-
-
Save makesomelayouts/bb3070f320d432b650f3e1c0fd95c8b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Converting a list of strings to a list of integers | |
| numbers = ['1', '2', '3', '4', '5'] | |
| result = list(map(int, numbers)) | |
| print(result) # [1, 2, 3, 4, 5] | |
| # Multiplying each element of a list by 2 | |
| numbers = [1, 2, 3, 4, 5] | |
| result = list(map(lambda x: x*2, numbers)) | |
| print(result) # [2, 4, 6, 8, 10] | |
| # Converting a list of string representations of numbers to a list of floats | |
| numbers = ['1.1', '2.2', '3.3', '4.4', '5.5'] | |
| result = list(map(float, numbers)) | |
| print(result) # [1.1, 2.2, 3.3, 4.4, 5.5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment