Python Forum
How search in multidim. list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How search in multidim. list
#2
>>> lis= [["id","type","city","price","rooms"],[0,"Flat","Prague",13000,5],[1,"Flat","Prague",1000,4],[2,"House","Prague",13020,10]]
>>> sorted([item for item in lis if item[1]=='Flat' and item[2]=='Prague'], key=lambda x: x[3])
[[1, 'Flat', 'Prague', 1000, 4], [0, 'Flat', 'Prague', 13000, 5]]
however this looks like list of lists created by reading entire csv file in memory. is that the case? You may want to use dict reader. it will make the code more readble
Reply


Messages In This Thread
How search in multidim. list - by jakubmudra - Dec-22-2017, 07:34 PM
RE: How search in multidim. list - by buran - Dec-22-2017, 09:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Excel File with a list of values huzzug 4 1,376 Nov-03-2023, 05:35 PM
Last Post: huzzug
  search a list or tuple for a specific type ot class Skaperen 8 2,075 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  Use one list as search key for another list with sublist of list jc4d 4 2,289 Jan-11-2022, 12:10 PM
Last Post: jc4d
  Search in an unsorted list amir_0402 2 19,186 Jun-04-2020, 10:25 PM
Last Post: deanhystad
  Alpha numeric element list search rhubarbpieguy 1 1,859 Apr-01-2020, 12:41 PM
Last Post: pyzyx3qwerty
  search binary file and list all founded keyword offset Pyguys 4 2,894 Mar-17-2020, 06:46 AM
Last Post: Pyguys
  Using Python to search through a list of urls jeremy 4 2,971 Dec-18-2019, 11:52 AM
Last Post: Malt
  Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV dn237 19 6,966 May-29-2019, 02:27 AM
Last Post: heiner55
  Linear search/searching for a word in a file/list kietrichards 3 3,538 Mar-08-2019, 07:58 PM
Last Post: Larz60+
  How to iterate through a list and search for a value fad3r 2 2,938 Jan-23-2018, 02:07 AM
Last Post: fad3r

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020