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

Print rows with certain values from a matrix

I have a matrix with a bike in each row. I would like to print all the rows containing a certain bike, f.ex "Trek". I am struggeling to find the correct code. The code below gives the following error message AttributeError: ‘list’ object has no attribute ‘values’. Anybody have any ideas on how to solve this?

bikes = [["Giant", "Steel", "58 cm", "1000"], ["Trek", "Aluminium", "56 cm", "6000"], 
    ["Trek", "Carbon", "60 cm", "8000"], ["Specialized", "Carbon", "60 cm", "10000"],
    ["Trek", "Aluminium", "58 cm", "1500"]]


print(bikes[bikes.values == "Trek"])

>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

Try this:

print([bike for bike in bikes if bike[0] == "Trek"])
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