like this
Also, do lists in #Python seriously not have a .map function?
Edit: Ohhh... I expected it to be a method on the list object itself.
Tech Cyborg reshared this.
Python map() function
The map() function is used to apply a given function to every item of an iterable, such as a list or tuple, and returns a map object (which is an iterator). Let's start with a simple example of using map() to convert a list of strings into a list ofGeeksforGeeks
Jonathan Lamothe likes this.
@flyingsquirrel Yup. And there's a multiprocessing version which can be useful if you're doing a very large csv but you probably want imap() for that one.
docs.python.org/3/library/mult…
multiprocessing — Process-based parallelism
Source code: Lib/multiprocessing/ Availability: not Android, not iOS, not WASI. This module is not supported on mobile platforms or WebAssembly platforms. Introduction: multiprocessing is a package...Python documentation
If you're looking for a function that applies another function to each element of a list and aggregates the results, it'd typically be done with a list comprehension:
[your_function(item) for item in your_list]
But you can also use list(map(your_function, your_list)) if you want. Basically, it's a built-in function rather than a method of the list class.
There's also a whole discussion to be had about lists vs generators and why you often wouldn't even need to make a list in the first place, but I won't get into that unless you want to know more.
Jonathan Lamothe likes this.
Christina
in reply to Jonathan Lamothe • • •