Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "L" which comes after each list value in Django

I did a query to get all the field values from a model.I stored the result in a queryset.

queryset=Books.objects.filter(book_type="comic")

Now when i filter this queryset :

query=queryset.filter(~Q(auther_id=1))
autherList=[]
for q in query:
    autherList.append(q.auther_id)
print autherList

It print the list as:

[3L, 4L, 9L, 13L, 53L, 53L, 102L, 111L, 111L, 111L, 111L] 

My question is : What does this L signify and how to remove it to get a simple list of ids.

I looked over this but could not find anything regarding this.

like image 949
Aman Gupta Avatar asked Dec 02 '22 13:12

Aman Gupta


1 Answers

The L denotes that the items are of long type.

The underlying database library (mysql may be?) is creating the long types while fetching them from the db. So they are long instead of plain old int.

You can convert them to integers using the int function.

>>> lng_number = 23L

>>> int_num = int(lng_number)

>>> int_num
23

If all the values are of the long type, you can use map like this:

>>> long_list = [1L, 3L, 10L]

>>> int_list = map(int, long_list)

>>> int_list
[1, 3, 10]

>>>
like image 116
masnun Avatar answered Dec 06 '22 10:12

masnun