## Fix Python – Sort tuples based on second parameter

I have a list of tuples that look something like this:
(“Person 1”,10)
(“Person 2”,8)
(“Person 3”,12)
(“Person 4”,20)

What I want produced, is the list sorted in ascending order, by the second value of the tuple. So L should be (“Person 2”, 8) after sorting.
How can I do this? Using Python 3.2.2 If that helps.
….

## Fix Python – Does Python have an immutable list?

Does python have immutable lists?
Suppose I wish to have the functionality of an ordered collection of elements, but which I want to guarantee will not change, how can this be implemented? Lists are ordered but they can be mutated.
….

## Fix Python – What’s the meaning of “(1,) == 1,” in Python?

I’m testing the tuple structure, and I found it’s strange when I use the == operator like:
>>> (1,) == 1,
Out: (False,)

When I assign these two expressions to a variable, the result is true:
>>> a = (1,)
>>> b = 1,
>>> a==b
Out: True

This questions is different from Python tuple trailing comma syntax rule in my view. I ask the group of expressi….

## Fix Python – Why in Python does “0, 0 == (0, 0)” equal “(0, False)”?

In Python (I checked only with Python 3.6 but I believe it should hold for many of the previous versions as well):
(0, 0) == 0, 0 # results in a two element tuple: (False, 0)
0, 0 == (0, 0) # results in a two element tuple: (0, False)
(0, 0) == (0, 0) # results in a boolean True

But:
a = 0, 0
b = (0, 0)
a == b # results in a boolean True

Why….

## Fix Python – Why do tuples take less space in memory than lists?

A tuple takes less memory space in Python:
>>> a = (1,2,3)
>>> a.__sizeof__()
48

whereas lists takes more memory space:
>>> b = [1,2,3]
>>> b.__sizeof__()
64

What happens internally on the Python memory management?
….

## Fix Python – How to find the maximum value in a list of tuples? [duplicate]

Finding max value in the second column of a nested list?

Closed 8 months ago.

I have a list with ~10^6 tuples in it like this:
[(101, 153), (255, 827), (361, 961), …]
^….

## Fix Python – Python : List of dict, if exists increment a dict value, if not append a new dict

I would like do something like that.

## Fix Python – How to extract the n-th elements from a list of tuples

I’m trying to obtain the n-th elements from a list of tuples.
I have something like:
elements = [(1,1,1),(2,3,7),(3,5,10)]

I wish to extract only the second elements of each tuple into a list:
seconds = [1, 3, 5]

I know that it could be done with a for loop but I wanted to know if there’s another way since I have thousands of tuples.
….

## Fix Python – How to convert list of tuples to multiple lists?

Suppose I have a list of tuples and I want to convert to multiple lists.
For example, the list of tuples is
[(1,2),(3,4),(5,6),]

Is there any built-in function in Python that convert it to:
[1,3,5],[2,4,6]

This can be a simple program. But I am just curious about the existence of such built-in function in Python.
….

## Fix Python – What is the syntax rule for having trailing commas in tuple definitions?

In the case of a single element tuple, the trailing comma is required.
a = (‘foo’,)

What about a tuple with multiple elements? It seems that whether the trailing comma exists or not, they are both valid. Is this correct? Having a trailing comma is easier for editing in my opinion. Is that a bad coding style?
a = (‘foo1’, ‘foo2’)
b = (‘foo1’, ‘foo….