0
How to search Relevant Book Id record in list?
For example u have one list in whic 5 book records are saved (each book have unique id number, name,author name,price) Means 20 values are stored in list Lets suppose one of the book have 3 unique id i want to search this id nd show all Related Information to that book ? How can i do tht
8 Respuestas
+ 4
hi, sounds a little bit confusing to me. You mentioned that each book has a unique id number. And then you say ‘... one of the book have 3 unique id ...’ Can you explaine it again?
And the other information that is missing is the programming language you want to use.
+ 4
hi, now it’s clear for me. I would suggest to store the data in a dict. This structure does always consists of a key: value pair. Key must be unique, value can contain data in our case a list with the detail data.
sample:
books = {
'1': ['Riverboat', 'Sam Gold', 22.50], ....}
Then you can search with the dict method .get for an id and print the detail data.
+ 2
hi Abdul, here my try inspired from your code
https://code.sololearn.com/c8NrSX9s71Z2/?ref=app
+ 1
Don't use a list. If you need to search, given an unique key, dictionaries are the better data structures.
+ 1
Daniel Adam Lothar thanks both of u i have completed my project thanksballot
+ 1
Lothar - clean code, but ... :D
A) If you use a list and your id is same as the index, use it to access the item directly! That results in O(1), so it's constant.
B) If that's not the case, use a dictionary so accessing is O(log n) with n the number of elements in your list
Otherwise your algorithm has O(n) and that's ... Not so good for large n.
Example:
log(1.000.000) = 6, compared to 1.000.000 ... is just a little better.
0
Sir let suppose on book unique id is "3"
I want to search the book whose id is "3"
Nd then it will print all the information of tht book
Like
Book id 3 Name aaaa Price 80 AutName Khan
The Language Is python
0
Thanks Allot