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

  • Home
  • SEARCH
  • 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 4571074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:27:09+00:00 2026-05-21T19:27:09+00:00

I’m a beginner in programming and also a beginner in Python. Below are the

  • 0

I’m a beginner in programming and also a beginner in Python. Below are the details for a better understanding of my issue.

Rooms = ['BlueRoom', 'RedRoom', 'GreenRoom', 'BlueRoom']
Availability = [5, 7, 3, 5]
Description = ['Blue', 'Red', 'Green', 'Blue']
Price = [120, 90, 150, 115]

What I need to have is, the same lists, but with the BlueRoom and all of the values in the same index position of the lists with the highest price removed, like this:

Rooms = ['RedRoom', 'GreenRoom', 'BlueRoom']
Availability = [7, 3, 5]
Description = ['Red', 'Green', 'Blue']
Price = [90, 150, 115]

I would really appreciate if someone could help me. This lists are just for example, but the lists I have to handle will have several rooms that are duplicated and I will have to do the same with each one.

EDIT: First of all, thank you all for the quick answers. On the other hand, I forgot to mention a little, but not less important at all, detail. I have to code using a very old interpreter, Jython version 2.2. So, some functions may not work for me.

  • 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-05-21T19:27:10+00:00Added an answer on May 21, 2026 at 7:27 pm

    As Jochen pointed out in a comment, you’re probably better off writing a class to store your information. Each instance of a class can store all the information relating to a single room.

    class Room(object):
        def __init__(self, name, availability, description, price):
            self.name = name
            self.availability = availability
            self.description = description
            self.price = price
    
    rooms = [Room('BlueRoom', 5, 'Blue', 120), ...]
    

    This way, all the information about a single room is always kept together, and you don’t have to worry about keeping different lists in sync. So you can just search the list to find the duplicate rooms and remove the ones you don’t want.

    For example, suppose you want to only keep the lowest-priced room matching a given description. The way I’d do that is

    import itertools
    
    # here is where you might insert the class code from above
    
    def namekey(room):
        return room.name
    def pricekey(room):
        return room.price
    sorted_rooms = sorted(rooms, namekey)
    

    First, you will need to sort the list rooms by name, in order for to the following code to work.

    cheapest_rooms = []
    

    That creates a new list that we’ll fill with the cheapest room with each name.

    for name, group in itertools.groupby(sorted_rooms, namekey):
    

    This will split the list of rooms into sub-lists by name.

        cheapest = min(group, key=pricekey)
    

    This finds the cheapest room out of the group.

        cheapest_rooms.append(cheapest)
    

    And that appends it to the list.

    All this can be condensed into

    import itertools
    
    # here is where you might insert the class code from above
    
    def namekey(room):
        return room.name
    def pricekey(room):
        return room.price
    [min(group, key=pricekey) for name, group \
          in itertools.groupby(sorted(rooms, namekey), namekey)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.