• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Python: Problem with sorting

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to learn Python. I am getting error in the following sorting program:




I am getting following errors:
/home/zulfi/PycharmProjects/sort/venv/bin/python /home/zulfi/PycharmProjects/sort/bubblesort.py
Traceback (most recent call last):
 File "/home/zulfi/PycharmProjects/sort/bubblesort.py", line 23, in <module>
   objTestSort.main()
 File "/home/zulfi/PycharmProjects/sort/bubblesort.py", line 16, in main
   self.sorting()
 File "/home/zulfi/PycharmProjects/sort/bubblesort.py", line 9, in sorting
   for j in range(TestSort.arr)-1:
TypeError: 'list' object cannot be interpreted as an integer

Process finished with exit code 1



Zulfi.
 
Bartender
Posts: 1204
22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at line 9.  What kind of argument does range() take and what does it return?  What kind of things can be operands for a subtraction?  Is there a function that can get the size of a list or array?
 
Zulfi Khan
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[size=12]Hi,
Thanks a lot for solving my problem. I am able to understand how we should be using range function with len.



Line#9 is:




Zulfi.[/size]
 
Our first order of business must be this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic