Reputation: 2194
I am using django to pull some data from the MySQL server I have. Currently I have it pulling a whole column of data (the "light" column) from the SQL server.
To do this I am using the following code
weather = weatherdata.objects.values_list('light', flat=True)
lightdata = list(weather)
When I do this the lightdata list looks like this:
[35L, 53L, 77L, 99L, 49L, 46L, 28L, 13L, 2L, 0L, 0L, 0L]
Those values are correct, its just there is an L at the end of each of these. How can I remove the L from this list?
Upvotes: 2
Views: 2400
Reputation: 3964
You can do something like this:
l = [35L, 53L, 77L, 99L, 49L, 46L, 28L, 13L, 2L, 0L, 0L, 0L]
l = [int(item) for item in l]
Also if you want to delete the replicated items:
l = [35L, 53L, 77L, 99L, 49L, 46L, 28L, 13L, 2L, 0L, 0L, 0L]
l = list(set(l))
l = [int(item) for item in l]
Upvotes: 4
Reputation: 2109
The L indicates a long integer.
>>> a = long(5)
>>> a
5L
>>> print a
5
You could convert the type of the elements in the list depending on your needs but it may not be necessary.
>>> b = [int(i) for i in list_of_longs]
>>> c = [str(i) for i in list_of_longs]
Edit: Seems Goin, Makoto and I were all typing answers at the same time.
Upvotes: 1
Reputation: 106389
The L at the end is indicative that it's a long type. It won't print through a print statement, and it's just telling you that the number stored here is definitely not an integer.
If you really wanted to get rid of them, then I suppose you could do something like the following:
lightdataNew = []
for num in lightdata:
lightdataNew.append(int(num))
lightdata = lightdataNew[:]
Upvotes: 2