I'm using a mySQL database on uwamps to store data on names and highscores of people who've played a game, and I need to get that data into a 2D array. So far, I've managed to get the data in as a 1D array, which looks like this when i print it:
[('name1', 4), ('name2', 3), ('name3', 2), ('name4', 6), ('name5', 1)]
I need what's inside each set of normal brackets to be a seperate list, like this:
[['name1', 4], ['name2', 3], ['name3', 2], ['name4', 6], ['name5', 1]]
Any idea how to do this?
sloth
101k21 gold badges183 silver badges224 bronze badges
1 Answer 1
just convert the touples to a list:
userscores=[('name1', 4), ('name2', 3), ('name3', 2), ('name4', 6), ('name5', 1)]
userscores=[list(user) for user in userscores]
answered Jan 14, 2020 at 10:26
Bendik Knapstad
1,4581 gold badge9 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
''mean its a string. You cannot remove that, its part of the python syntax not the text itself. And please provide an example of what your output should look like