Search code examples
pythonmysqlarraysuwamp

Python: How to split input from database into a 2d array


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?


Solution

  • 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]