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 8595055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:20:44+00:00 2026-06-12T00:20:44+00:00

I don’t know how to keep this simple… I’d like someone too look at

  • 0

I don’t know how to keep this simple… I’d like someone too look at my code and tell me why a function of mine is not working like it should…

I have a class:

 class PriorityQueue(object):
'''A class that contains several methods dealing with queues.'''

    def __init__(self):
        '''The default constructor for the PriorityQueue class, an empty list.'''
        self.q = []

    def insert(self, number):
        '''Inserts a number into the queue, and then sorts the queue to ensure that the number is in the proper position in the queue.'''
        self.q.append(number)
        self.q.sort()

    def minimum(self):
        '''Returns the minimum number currently in the queue.'''
        return min(self.q)

    def removeMin(self):
        '''Removes and returns the minimum number from the queue.'''
        return self.q.pop(0)

    def __len__(self):
        '''Returns the size of the queue.'''
        return self.q.__len__()

    def __str__(self):
        '''Returns a string representing the queue.'''
        return "{}".format(self.q)

    def __getitem__(self, key):
        '''Takes an index as a parameter and returns the value at the given index.'''
        return self.q[key]

    def __iter__(self):
        return self.q.__iter__()

And I have this function which will take a text file, and run it through some methods in my class:

def testQueue(fname):
    infile = open(fname, 'r')
    info = infile.read()
    infile.close()
    info = info.lower()
    lstinfo = info.split()
    queue = PriorityQueue()
    for item in range(len(lstinfo)):
        if lstinfo[item] == "i":
            queue.insert(eval(lstinfo[item + 1]))
        if lstinfo[item] == "s":
            print(queue)
        if lstinfo[item] == "m":
            queue.minimum()
        if lstinfo[item] == "r":
            queue.removeMin()
        if lstinfo[item] == "l":
            len(queue)
        #if lstinfo[item] == "g":

What is not working for me is my calls to queue.minimum and queue.removeMin().

I’m completely baffled because if I do it manually in the shell, it all works, when I am reading the file and taking the instructions from the letters in my file, it also works, but minimum and removeMin() will not display the values in the shell, removeMin() however WILL remove the lowest number from the list.

What am I doing wrong that it’s not displaying what it is doing, like the class methods define?

IE:

 def minimum(self):
     return min(self.q)

Shouldn’t it display the minimum when I call it from my function?

  • 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-12T00:20:45+00:00Added an answer on June 12, 2026 at 12:20 am

    No, def minimum(self): return min(self.q) won’t display anything when called. It’ll only display something if you print the output, as in print(queue.minimum()). The exception to this is when executing code from the Python prompt/REPL, which prints expressions by default (unless they’re None).

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

Sidebar

Related Questions

Don't know if this is possible, but I have some code like this: val
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
I don't know why, but this code worked for me a month ago... maybe
don't know better title for this, but here's my code. I have class user
Don't know how to frase this but I found this code wich works as
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple

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.