Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:01:23+00:00 2026-06-03T22:01:23+00:00

I have a csv file which is something like this: book_store_id book_price name 1

  • 0

I have a csv file which is something like this:

 book_store_id  book_price   name

 1              200.0        foo
 1              320.0        bar
 2              220.0        foobar
 2              280.0        foo

So.. this is a huge list..

Now I am trying to find out that if the input is “foo”

then since bookstore id 1 has “foo” marked lowest price, then I want to return “book_store” 1

Now How I am doing this is creating an inverted index which returns something like

foo:1,2 
bar:1
foobar:2

and so on, and then a seperate dictionary where I am maintaining the price of book in a store.. but is this the best way out to solve this out.

What is the most efficient way to solve this problem in python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:01:24+00:00Added an answer on June 3, 2026 at 10:01 pm

    I would create a third data structure (python dict, or database table or whatever).

    the data structures key should be the name (assuming name is unique).

    The value this “name” key points at should be the minimum price.

    Every time you insert a new book, or update the price of a book, look up the books minimum price in the third data structure, if it is less than the minimum price, set the new minimum price.

    Don’t forget, if you delete a book, or increase its price, make sure you update the minimum.
    (you could add another column so each book has a boolean “is current minimum”. Then on price increase you only need to update the minimum if this is true.

    The problem is, then you need to find the next best minimum when you remove the old minimum.

    This is where it’s good to have a heapq

    python has a nice implementation of heapq here:
    http://docs.python.org/library/heapq.html

    Otherwise you have to loop through all values to find the new minimum upon every price increase, or you have to store the 5 best prices each time, say.

    have fun 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large CSV file with many columns, something like this: id, col1,
I have a Excel CSV files with employee records in them. Something like this:
I have a .csv file like this (; as a delimiter): Group1; User_A Group1;
Little Background: I have csv file which has lots of rows and each row
I have a csv file which may have empty or blank rows. I want
I have a CSV file which has the following format: id,case1,case2,case3 Here is a
Possible Duplicate: Prepend lines to file in Java I have a CSV-file which supports
I have a csv file from which I have to populate different tables in
I have a Testing project that contains a csv file which a webtest uses
I have a PHP app that creates a CSV file which is forced to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.