Convert list to tuple in Python
I'm trying to convert a list to a tuple.
Most solutions on Google offer the following code:
l = [4,5,6]
tuple(l)
However, the code results in an error message when I run it:
TypeError: 'tuple' object is not callable
How can …
How to sort a list/tuple of lists/tuples by the element at a given index?
I have some data either in a list of lists or a list of tuples, like this:
data = [[1,2,3], [4,5,6], [7,8,9]]
data = [(1,2,3), (4,5,6), (7,8,9)]
And I want to sort by the 2nd element in the subset. Meaning, sorting by 2,5,8 where 2 is from (1,2,3), 5 is from (4,5,6). What …
Convert tuple to list and back
I'm currently working on a map editor for a game in pygame, using tile maps.
The level is built up out of blocks in the following structure (though much larger):
level1 = (
(1,1,1,1,1,1)
(1,0,0,0,0,1)
(1,0,0,0,0,1)
(1,0,0,0,0,1)
(1,0,0,0,0,1)
(1,1,1,1,1,1))
where "1" is a block that's a wall and "0" is …