About 412,000 results
Open links in new tab
  1. python map over list of tuples - Stack Overflow

    Dec 30, 2021 · You don't need map for something like that, and in fact would gain readability by using a list comprehension: >>> [RPS_winner(a, b) for a, b in rounds] [1, 2, 2, 2, 0, 1, 1, 2, 0, 1] Another possibility is to use itertools.starmap , which is designed precisely for that:

  2. python - Understanding the map function - Stack Overflow

    Jun 11, 2012 · For map(tuple, array), array would be an iterable of iterables (think a list of lists), and it gives you back each inner list turned into a tuple. In general, it is the first sentence of the documentation of any function that matters the most. If you understand that, you get the gist of it.

  3. Python List VS Array VS Tuple - GeeksforGeeks

    Feb 19, 2025 · In Python, List, Array and Tuple are data structures for storing multiple elements. Lists are dynamic and hold mixed types, Arrays are optimized for numerical data with the same type and Tuples are immutable, ideal for fixed collections. Choosing the right one depends on performance and data needs. List in Python

  4. Python map() function - GeeksforGeeks

    Oct 23, 2024 · 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 of integers.

  5. Create a List of Tuples in Python - GeeksforGeeks

    Feb 14, 2025 · map() is the most efficient approach to convert a list of lists into a list of tuples. It applies the tuple() constructor to each sublist, transforming each inner list into a tuple. This approach is optimized, making it faster than list comprehension when working with nested lists.

  6. 5 Best Ways to Convert Python List of Tuples to Map

    Feb 23, 2024 · One common approach to convert a list of tuples to a map is by iterating through each tuple with a for loop and assigning the key-value pairs to a new dictionary. This method gives a clear understanding of the process and allows for additional logic during the conversion.

  7. 5 Best Ways to Convert a Python List of Tuples to a 2D Array

    Feb 23, 2024 · Lambda functions offer a quick, inline option for converting each tuple in a list to a list, especially when combined with the map() function. Here’s an example: tuples_list = [(1, 2), (3, 4), (5, 6)] array_2d = list(map(lambda x: list(x), tuples_list)) Output: [[1, 2], [3, 4], [5, 6]]

  8. Learn How to Use the Python Map Function on Lists, Sets and Tuples

    Nov 25, 2019 · Find out the uses of Python map function to apply functions to objects in sequences. This tutorial on Python map focuses on lists, tuples, sets and more!

  9. Apply a function to items of a list with map() in Python

    May 15, 2023 · In Python, you can use map() to apply built-in functions, lambda expressions (lambda), functions defined with def, etc., to all items of iterables, such as lists and tuples. Built-in Functions - map() ...

  10. How to Transform List Elements with Python map() Function - Python

    Python provides a nicer way to do this kind of task by using the map() built-in function. The map() function iterates over all elements in a list (or a tuple), applies a function to each, and returns a new iterator of the new elements. The following shows the basic syntax of the map() function: iterator = map(fn, list) Code language: Python ...

Refresh