L
lokeshkoppaka
i need to write a code which can sort the list in order of 'n' without use builtin functions
can anyone help me how to do?
can anyone help me how to do?
i need to write a code which can sort the list in order of 'n' without use builtin functions
can anyone help me how to do?
i need to write a code which can sort the list in order of 'n' without use builtin functions
can anyone help me how to do?
i need to write a code which can sort the list in order of 'n' without use builtin functions
can anyone help me how to do?
Note:
the list only contains 0's,1's,2's
need to sort them in order of 'n'
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.
ChrisA
Note:
the list only contains 0's,1's,2's
need to sort them in order of 'n'
but i need to do it with out using builtin functions
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
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
Date: Fri, 24 May 2013 23:05:17 -0700
Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
From: (e-mail address removed)
To: (e-mail address removed) [...]
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
----------------------------------------count[2] = len(l)Date: Fri, 24 May 2013 23:05:17 -0700
1. No in-built functions should be used
Date: Sat, 25 May 2013 18:28:32 +1000
Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
From: (e-mail address removed)
To: (e-mail address removed)
----------------------------------------count[2] = len(l)Date: Fri, 24 May 2013 23:05:17 -0700
1. No in-built functions should be used
Fail!
ChrisA
----------------------------------------
lol I forgot to include this monkey patch!
def length(l):
x=0
y=l[:]
while y:
x+=1
y.pop()
return x
Date: Sat, 25 May 2013 18:47:24 +1000
Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
From: (e-mail address removed)
To: (e-mail address removed)
----------------------------------------
lol I forgot to include this monkey patch!
def length(l):
x=0
y=l[:]
while y:
x+=1
y.pop()
return x
Nice. Now eliminate abs (easy) and range.
ChrisA
lol
def absolute(x):
return x if x>0 else -x
def reach(x):
y=[]
z=0
while z<x:
y.append(z)
z+=1
return y
Date: Sat, 25 May 2013 19:01:09 +1000
Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
From: (e-mail address removed)
To: (e-mail address removed) [...]
Very good. You are now in a position to get past the limitations of a
restricted-environment eval/exec. Avoiding builtins is actually a fun
skill to hone.
ChrisA
----------------------------------------Date: Sat, 25 May 2013 19:01:09 +1000
Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions??
From: (e-mail address removed)
To: (e-mail address removed) [...]
Very good. You are now in a position to get past the limitations of a
restricted-environment eval/exec. Avoiding builtins is actually a fun
skill to hone.
ChrisA
I'm glad he didn't ask for a Pseudo-RNG without built-ins!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.