help how to sort a list in order of 'n' in python without using inbuilt functions??
lokeshkoppaka at gmail.com
lokeshkoppaka at gmail.com
Sat May 25 02:05:17 EDT 2013
On Saturday, May 25, 2013 11:27:38 AM UTC+5:30, Steven D'Aprano wrote:
> On Fri, 24 May 2013 22:39:06 -0700, lokeshkoppaka wrote:
>
>
>
> > On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote:
>
>
>
> >> In that case, you're not really ordering them, you're counting them.
>
> >> Look at the collections module; you can very easily figure out how
>
> >> many of each there are, and then reconstruct the list afterward.
>
> >
>
> > but i need to do it with out using builtin functions
>
>
>
>
>
> How would you, an intelligent human being count them?
>
>
>
> Describe how you would count them in English, or whatever your native
>
> language is.
>
>
>
> "First I would start a tally for the number of zeroes, tally = 0. Then I
>
> look at each item in turn, and if it is 0, I add one to the tally. When I
>
> get to the end, I the number of zeroes is equal to the tally.
>
>
>
> Then I do the same for the number of ones, and the number of twos."
>
>
>
> Now turn that into Python code.
>
>
>
> tally = 0
>
> for item in list_of_items:
>
> if item == 0:
>
> tally = tally + 1
>
>
>
> print "The number of zeroes equals", tally
>
>
>
>
>
>
>
> --
>
> Steven
ya steven i had done the similar logic but thats not satisfying my professor
he had given the following constrains
1. No in-built functions should be used
2. we are expecting a O(n) solution
3. Don't use count method
More information about the Python-list
mailing list