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

The Archive Base Latest Questions

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

I have a .py file that takes a list, finds the lowest number, puts

  • 0

I have a .py file that takes a list, finds the lowest number, puts it into a new array, removes the lowest number from the first array, and repeats until the original array returns contains no more items:

def qSort(lsort):
    listlength = len(lsort)
    sortedlist = list()
    if listlength == 0:
        return lsort
    else:
        while listlength > 0:
            lmin = min(lsort)
            sortedlist.append(lmin)
            lsort.remove(lmin)
            listlength = len(lsort)
        return sortedlist

Now another .py file imports the qSort and runs it on some list, saving it to a variable. Then I try to use the .reverse() command on the list and I end up getting it as a NoneType. I try to use reversed(), but all it does is say "<listreverseiterator object at 0xSomeRandomHex>":

from qSort import qSort #refer to my first Pastebin

qSort = qSort([5,42,66,1,24,5234,62])
print qSort #this prints the sorted list
print type(qSort) #this prints <type 'list'>
print qSort.reverse() #this prints None
print reversed(qSort) #this prints "<listreverseiterator object at 0xSomeRandomHex>"

Can anyone explain why I can’t seem to reverse the list, no matter what I do?

  • 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-21T20:52:10+00:00Added an answer on May 21, 2026 at 8:52 pm

    As jcomeau mentions, the .reverse() function changes the list in place. It does not return the list, but rather leaves qSort altered.

    If you want to ‘return’ the reversed list, so it can be used like you attempt in your example, you can do a slice with a direction of -1

    So replace print qSort.reverse() with print qSort[::-1]


    You should know slices, its useful stuff. I didn’t really see a place in the tutorial where it was all described at once, (http://docs.python.org/tutorial/introduction.html#lists doesn’t really cover everything) so hopefully here are some illustrative examples.

    Syntax is: a[firstIndexInclusive:endIndexExclusive:Step]

    >>> a = range(20)
    >>> a
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    >>> a[7:] #seventh term and forward
    [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    >>> a[:11] #everything before the 11th term
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    >>> a[::2] # even indexed terms.  0th, 2nd, etc
    [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
    >>> a[4:17]
    [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
    >>> a[4:17:2]
    [4, 6, 8, 10, 12, 14, 16]
    >>> a[::-1]
    [19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
    >>> a[19:4:-5]
    [19, 14, 9]
    >>> a[1:4] = [100, 200, 300] #you can assign to slices too
    >>> a
    [0, 100, 200, 300, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that takes a condition and item, from an array of
I have a small job that takes a text file of email/zip codes and
I have a function that takes 2 parameters : 1 = XML file, 2
I have a perl program that takes input and output file arguments, and I'd
I have a nant script that ... 1. takes the content of disc-file 2.
I have a simple Java program that takes a .jrxml file, compiles it, then
I have code to read in the version number from a make file. VERSION_ID=map(int,re.match(VERSION_ID\s*=\s*(\S+),open(version.mk).read()).group(1).split(.))
I have been working on designing a file server that could take the load
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace

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.