Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract only numbers from a list of tuples

poi = booking_models.TestBooking.objects.filter(customer_visit=instance).values_list("package__package_name", "amount").order_by("package").distinct()

[(None, 392.0), (None, 530.0), ('RahulNewPaackage', 3999.0), ('Suraj pkg today all', 699.0), ('suraj 44', 599.0)]

I am learning python and django and trying to get only numbers from this output(poi). I want to get this in a list like this [392.0, 530.0, 3999.0, 699.0, 599.0]. As poi will iterate many times so every time till the last item there will be output of list of numbers. How to achieve this ? Any help will be really appreciated. Thank you !!

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You each time want the second item, so you can work with list comprehension:

[x for _, x in poi]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading