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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:41:17+00:00 2026-06-06T20:41:17+00:00

I am trying to implement a partition function for quicksort in Python. def partition(ls):

  • 0

I am trying to implement a partition function for quicksort in Python.

def partition(ls):
  if len(ls) == 0:
    return
  pivot = ls[0]
  i, j = 1
  while j < len(ls):
    if ls[j] <= pivot:
      i += 1
      temp = ls[i]
      ls[i] = ls[j]
      ls[j] = temp
    j += 1
  ls[0] = ls[i]
  ls[i] = pivot

However, Python issues this error when I call quicksort.partition([1,2,3]).

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "quicksort.py", line 5, in partition
    i, j = 1
TypeError: 'int' object is not iterable

What is this error saying? Of course, int objects are not iterable, but when did I ever iterate over an int object?

  • 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-06T20:41:19+00:00Added an answer on June 6, 2026 at 8:41 pm

    When you list multiple targets separated by commas on the left of an assignment, it tries to iterate over the right hand side and assign pieces to the pieces on the left. So if you do x, y = (1, 2) then x will be 1 and y will be 2.

    If you want to make i and j both be 1, do i = j = 1.

    (Note that this binds both variables to the same object. It’s fine for this case, but if you are assigning a mutable object (like x = y = []) you should remember that both x and y will be pointing to the same list, so mutations will affect both x and y.)

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

Sidebar

Related Questions

I am trying to implement quicksort in python: def partition(ls): if len(ls) == 0:
I'm trying to implement quicksort in Python using 2 main functions - partition and
Trying to implement a function in my linkedlist class that will return total amount
Trying to implement a search similar to here .This searches properties based on city,locality,property
Ok well I'm trying implement something similar to the 'undo' function in many image
Trying to implement the signature verification of inapp billing on my server (Django/Python). I
I've a webbrowser control and I'm trying implement IDocHostUIHandler in the container. However since
I have this weird kind of error. I am trying implement basic Euclidean algorithm
Trying to implement a shell, mainly piping. I've written this test case which I
im trying to implement the recursive Ackermann-Peter-Function in x86 NASM-Assembly. The Function is defined

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.