FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programmingWithPythonCode/iteration/map.py at main · thomasWeise/programmingWithPythonCode · GitHub
thomasWeise
programmingWithPythonCode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programmingWithPythonCode
/
iteration
/
map.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
17 lines (13 loc) · 681 Bytes
Breadcrumbs
programmingWithPythonCode
/
iteration
/
map.py
Copy path
File metadata and controls
17 lines (13 loc) · 681 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""Examples of `map`: Transform the elements of sequences."""
# A string with comma-separated values (csv).
csv_text
:
str
=
"12,23,445,3,12,6,-3,5"
# Convert the csv data to ints by using `split` and `map`, then filter.
for
k
in
filter
(
lambda
x
:
x
>
20
,
map
(
int
,
csv_text
.
split
(
","
))):
print
(
f"found value
{
k
}
."
)
# Obtain all unique square numbers using `map` and `set`.
csv_text_sqrs
:
set
[
int
]
=
set
(
map
(
lambda
x
:
int
(
x
)
**
2
,
csv_text
.
split
(
","
)))
print
(
f"csv_text_sqrs:
{
csv_text_sqrs
}
"
)
# Get the maximum word length by using `map`, `len`, and `max`.
words
:
list
[
str
]
=
[
"Hello"
,
"world"
,
"How"
,
"are"
,
"you"
]
print
(
f"longest word length:
{
max
(
map
(
len
,
words
))
}
"
)
Back
|
FazBrowse Home
|
New Git URL