Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45867 > unrolled thread
| Started by | lokeshkoppaka@gmail.com |
|---|---|
| First post | 2013-05-24 01:04 -0700 |
| Last post | 2013-05-25 17:59 +0300 |
| Articles | 20 on this page of 42 — 11 participants |
Back to article view | Back to comp.lang.python
help how to sort a list in order of 'n' in python without using inbuilt functions?? lokeshkoppaka@gmail.com - 2013-05-24 01:04 -0700
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-24 18:12 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Dave Angel <davea@davea.name> - 2013-05-24 08:33 -0400
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-24 16:06 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? lokeshkoppaka@gmail.com - 2013-05-24 22:15 -0700
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 15:24 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? lokeshkoppaka@gmail.com - 2013-05-24 22:39 -0700
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 15:43 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-25 05:57 +0000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? lokeshkoppaka@gmail.com - 2013-05-24 23:05 -0700
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 16:12 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 10:53 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 18:28 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 11:43 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 18:47 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 11:54 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 19:01 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 12:10 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-25 19:14 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-25 14:28 +0000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Fábio Santos <fabiosantosart@gmail.com> - 2013-05-25 15:46 +0100
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-25 16:03 +0100
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-26 01:41 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-26 03:09 +0000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-26 14:02 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 20:12 +0300
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 20:17 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-26 03:23 +1000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-26 03:38 +0000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Dan Sommers <dan@tombstonezero.net> - 2013-05-26 04:06 +0000
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Chris Angelico <rosuav@gmail.com> - 2013-05-26 14:28 +1000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 20:34 +0300
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 12:30 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-25 13:01 +0100
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Roy Smith <roy@panix.com> - 2013-05-25 10:03 -0400
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Dave Angel <davea@davea.name> - 2013-05-25 10:27 -0400
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-25 14:30 +0000
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 20:07 +0300
RE: help how to sort a list in order of 'n' in python without using inbuilt functions?? Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-25 20:45 +0300
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? rusi <rustompmody@gmail.com> - 2013-05-24 22:43 -0700
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Roy Smith <roy@panix.com> - 2013-05-25 09:29 -0400
Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-05-25 17:59 +0300
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Fábio Santos <fabiosantosart@gmail.com> |
|---|---|
| Date | 2013-05-25 15:46 +0100 |
| Message-ID | <mailman.2133.1369493215.3114.python-list@python.org> |
| In reply to | #45994 |
[Multipart message — attachments visible in raw view] — view raw
On 25 May 2013 15:35, "Steven D'Aprano" < steve+comp.lang.python@pearwood.info> wrote: > > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > > > def random_number(): > > return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundreds* of times and not once did it come up seven! > > > > -- > Steven > -- > http://mail.python.org/mailman/listinfo/python-list Try flipping a coin. I flipped one a couple of times and got the seventh face once.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-05-25 16:03 +0100 |
| Message-ID | <mailman.2135.1369494225.3114.python-list@python.org> |
| In reply to | #45994 |
On 25/05/2013 15:28, Steven D'Aprano wrote: > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > >> def random_number(): >> return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundreds* of times and not once did it come up seven! > > > Lies, damn lies and statistics? :) -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-26 01:41 +1000 |
| Message-ID | <mailman.2137.1369496527.3114.python-list@python.org> |
| In reply to | #45994 |
On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > >> def random_number(): >> return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundreds* of times and not once did it come up seven! You've obviously never used a REAL set of dice. Now, I have here with me a set used for maths drill (to be entirely accurate, what I have here is the company's stock of them, so there are multiples of each of these - anyone need to buy dice?) with everything except the classic 1 through 6 that everyone knows: * Six sides, faces marked 7 through 12 * Six sides, faces marked "+x-\xf7+" and a "wild" marker (yes, two of +) * Ten sides, numbered 0 through 9 * Eight sides, numbered 1 through 8 * Twelve sides, as above * Twenty sides, as above Now, tabletop roleplayers will recognize the latter four as the ones notated as d10, d8, d12, and d20, but these are NOT for gameplay, they are for serious educational purposes! Honest! Anyway, all of those can roll a 7... well, one of them has to roll a \xf7, but close enough right? Plus, if you roll 2d6 (that is, two regular six-sided dice and add them up), 7 is statistically the most likely number to come up with. Therefore it IS random. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-05-26 03:09 +0000 |
| Message-ID | <51a17cff$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #46005 |
On Sun, 26 May 2013 01:41:58 +1000, Chris Angelico wrote:
> On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote:
>>
>>> def random_number():
>>> return 7
>>
>> I call shenanigans! That value isn't generated randomly, you just made
>> it up! I rolled a die *hundreds* of times and not once did it come up
>> seven!
>
> You've obviously never used a REAL set of dice.
You're right, all my dice are eight-sided and complex:
1+0i
1+1i
1-1i
-1+0i
-1+1i
-1-1i
:-)
But seriously, I have various D&D style gaming dice, d4, d6, d8, d12, d20
and d30. But I thought the opportunity for a joke was more important than
pedantic correctness :-)
> Now, I have here with me
> a set used for maths drill (to be entirely accurate, what I have here is
> the company's stock of them, so there are multiples of each of these -
> anyone need to buy dice?)
Are you serious? What's the cost, posted to Melbourne?
> with everything except the classic 1 through 6 that everyone knows:
>
> * Six sides, faces marked 7 through 12
> * Six sides, faces marked "+x-\xf7+" and a "wild" marker
> (yes, two of +)
Oh, you mean ÷ (division sign)! Why didn't you say so? :-P
And another thing, shame on you, you mean × not x. It's easy to find too:
py> from unicodedata import lookup
py> print(lookup("MULTIPLICATION SIGN"))
×
> * Ten sides, numbered 0 through 9
> * Eight sides, numbered 1 through 8
> * Twelve sides, as above
> * Twenty sides, as above
>
> Now, tabletop roleplayers will recognize the latter four as the ones
> notated as d10, d8, d12, and d20, but these are NOT for gameplay, they
> are for serious educational purposes! Honest!
>
> Anyway, all of those can roll a 7... well, one of them has to roll a
> \xf7, but close enough right?
I don't think so...
> Plus, if you roll 2d6 (that is, two
> regular six-sided dice and add them up), 7 is statistically the most
> likely number to come up with. Therefore it IS random.
Yes, but if you subtract them the most common is 0, if you multiply the
most common are 6 or 12, and if you divide the most common is 1. If you
decide on the operation randomly, using the +-×÷+ die above (ignoring
wildcards), the most common result is 6. The probability of getting a 7
is just 1/15.
from collections import Counter
from operator import add, sub, mul, truediv as div
ops = (add, sub, mul, div, add)
Counter(op(i, j) for op in ops for i in range(1, 7) for j in range(1, 7))
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-26 14:02 +1000 |
| Message-ID | <mailman.2158.1369540952.3114.python-list@python.org> |
| In reply to | #46031 |
On Sun, May 26, 2013 at 1:09 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> You're right, all my dice are eight-sided and complex:
>
> 1+0i
> 1+1i
> 1-1i
> -1+0i
> -1+1i
> -1-1i
>
>
> :-)
Now THAT is a dice of win!
>> Now, I have here with me
>> a set used for maths drill (to be entirely accurate, what I have here is
>> the company's stock of them, so there are multiples of each of these -
>> anyone need to buy dice?)
>
> Are you serious? What's the cost, posted to Melbourne?
$1 each, postage probably $5 for any number. Or there may even be
option to pick up / hand deliver, depending on where in Melb you are.
http://www.kepl.com.au/ - company's winding down, but we still have stock.
> Oh, you mean ÷ (division sign)! Why didn't you say so? :-P
I tend to stick to ASCII in these posts. :)
> And another thing, shame on you, you mean × not x. It's easy to find too:
>
> py> from unicodedata import lookup
> py> print(lookup("MULTIPLICATION SIGN"))
> ×
I'm aware of that, but see above, I stick to ASCII where possible. The
faces would be better represented with some of the other digits (the
bolded ones, perhaps), but I used the ASCII digits. :)
>> Plus, if you roll 2d6 (that is, two
>> regular six-sided dice and add them up), 7 is statistically the most
>> likely number to come up with. Therefore it IS random.
>
> Yes, but if you subtract them the most common is 0, if you multiply the
> most common are 6 or 12, and if you divide the most common is 1. If you
> decide on the operation randomly, using the +-×÷+ die above (ignoring
> wildcards), the most common result is 6. The probability of getting a 7
> is just 1/15.
>
> from collections import Counter
> from operator import add, sub, mul, truediv as div
> ops = (add, sub, mul, div, add)
> Counter(op(i, j) for op in ops for i in range(1, 7) for j in range(1, 7))
LOL! I never thought to go THAT far into the analysis..... Nice one!
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 20:12 +0300 |
| Message-ID | <mailman.2140.1369501974.3114.python-list@python.org> |
| In reply to | #45994 |
---------------------------------------- > From: steve+comp.lang.python@pearwood.info > Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? > Date: Sat, 25 May 2013 14:28:33 +0000 > To: python-list@python.org > > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > >> def random_number(): >> return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundreds* of times and not once did it come up seven! lol It worked fine on my d8! lol
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 20:17 +0300 |
| Message-ID | <mailman.2141.1369502281.3114.python-list@python.org> |
| In reply to | #45994 |
---------------------------------------- > Date: Sun, 26 May 2013 01:41:58 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? > From: rosuav@gmail.com > To: python-list@python.org > > On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano > <steve+comp.lang.python@pearwood.info> wrote: >> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: >> >>> def random_number(): >>> return 7 >> >> I call shenanigans! That value isn't generated randomly, you just made it >> up! I rolled a die *hundreds* of times and not once did it come up seven! > > You've obviously never used a REAL set of dice. Now, I have here with > me a set used for maths drill (to be entirely accurate, what I have > here is the company's stock of them, so there are multiples of each of > these - anyone need to buy dice?) with everything except the classic 1 > through 6 that everyone knows: > > * Six sides, faces marked 7 through 12 > * Six sides, faces marked "+x-\xf7+" and a "wild" marker (yes, two of +) > * Ten sides, numbered 0 through 9 > * Eight sides, numbered 1 through 8 > * Twelve sides, as above > * Twenty sides, as above > > Now, tabletop roleplayers will recognize the latter four as the ones > notated as d10, d8, d12, and d20, but these are NOT for gameplay, they > are for serious educational purposes! Honest! > > Anyway, all of those can roll a 7... well, one of them has to roll a > \xf7, but close enough right? Plus, if you roll 2d6 (that is, two > regular six-sided dice and add them up), 7 is statistically the most > likely number to come up with. Therefore it IS random. > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list def f(x): return x+1 or you can just go: f(roll_d6()) ;)
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-26 03:23 +1000 |
| Message-ID | <mailman.2142.1369502632.3114.python-list@python.org> |
| In reply to | #45994 |
On Sun, May 26, 2013 at 3:17 AM, Carlos Nepomuceno <carlosnepomuceno@outlook.com> wrote: > def f(x): > return x+1 > > or you can just go: > > f(roll_d6()) Hmm. Interesting. So now we have a question: Does adding 1 to a random number make it less random? It adds determinism to the number; can a number be more deterministic while still no less random? Ah! I know. The answer comes from common sense: a = random() # a is definitely a random number a -= random() # a is no longer random, we subtracted all the randomness from it Of course, since number-number => number, a is still a number. And so we can conclude that adding 1 to a random dice roll does indeed leave all the randomness still in it. But wait! That means we can do better!! a = random() # a is a random number a *= 5 # a is clearly five times as random now! ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-05-26 03:38 +0000 |
| Message-ID | <51a183a4$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #46011 |
On Sun, 26 May 2013 03:23:44 +1000, Chris Angelico wrote: > Does adding 1 to a random > number make it less random? It adds determinism to the number; can a > number be more deterministic while still no less random? > > Ah! I know. The answer comes from common sense: [snip spurious answer] I know you're being funny, but in fact adding a constant to a random variable still leaves it equally random. Adding, multiplying, dividing or subtracting a constant from a random variable X just shifts the possible values X can take, it doesn't change the shape of the distribution. However, adding two random variables X and Y does change the distribution. In fact, a very cheap way of simulating an almost normally distributed random variable is to add up a whole lot of uniformly distributed random variables. Adding up 12 calls to random.random(), and subtracting 6, gives you a close approximation to a Gaussian random variable with mean 0 and standard deviation 1. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Dan Sommers <dan@tombstonezero.net> |
|---|---|
| Date | 2013-05-26 04:06 +0000 |
| Message-ID | <eTfot.4451$EM6.288@newsfe04.iad> |
| In reply to | #46034 |
On Sun, 26 May 2013 03:38:12 +0000, Steven D'Aprano wrote: > ... adding a constant to a random variable still leaves it equally > random. Adding, multiplying, dividing or subtracting a constant from a > random variable X just shifts the possible values X can take ... That's mathematically true, but this is the Python mailing list. Adding, subtracting, or dividing by a sufficiently large constant loses all the randomness. Python 3.2.4 (default, May 8 2013, 20:55:18) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import random >>> random.random() + 1e200 1e+200 >>> random.random() - 1e200 -1e+200 >>> random.random() / 1e309 0.0 But you knew that. ;-) Dan
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-26 14:28 +1000 |
| Message-ID | <mailman.2163.1369542526.3114.python-list@python.org> |
| In reply to | #46034 |
On Sun, May 26, 2013 at 1:38 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > On Sun, 26 May 2013 03:23:44 +1000, Chris Angelico wrote: > >> Does adding 1 to a random >> number make it less random? It adds determinism to the number; can a >> number be more deterministic while still no less random? >> >> Ah! I know. The answer comes from common sense: > [snip spurious answer] > > I know you're being funny, but in fact adding a constant to a random > variable still leaves it equally random. Adding, multiplying, dividing or > subtracting a constant from a random variable X just shifts the possible > values X can take, it doesn't change the shape of the distribution. In real numbers, that's correct. However, computers don't work with real numbers, so there's the very, uhh, REAL possibility that some of the entropy will be lost. For instance, multiplying and dividing when working with integers results in truncation, and adding huge numbers to small floats results in precision loss. I was deliberately playing around, but unfortunately there have been many people who've genuinely thought things similar to what I was saying - and then implemented into code. > However, adding two random variables X and Y does change the > distribution. In fact, a very cheap way of simulating an almost normally > distributed random variable is to add up a whole lot of uniformly > distributed random variables. Adding up 12 calls to random.random(), and > subtracting 6, gives you a close approximation to a Gaussian random > variable with mean 0 and standard deviation 1. Yep. The more dice you roll, the more normal the distribution. Which means that d100 is extremely swingy, but 11d10-10 is much less so, and 99d2-98 quite stable. The more randomness you add, the more predictable the result. <quote source="Jubal Early">Does that seem right to you?</quote> ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 20:34 +0300 |
| Message-ID | <mailman.2146.1369503245.3114.python-list@python.org> |
| In reply to | #45994 |
---------------------------------------- > Date: Sun, 26 May 2013 03:23:44 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? > From: rosuav@gmail.com > To: python-list@python.org > > On Sun, May 26, 2013 at 3:17 AM, Carlos Nepomuceno > <carlosnepomuceno@outlook.com> wrote: >> def f(x): >> return x+1 >> >> or you can just go: >> >> f(roll_d6()) > > Hmm. Interesting. So now we have a question: Does adding 1 to a random > number make it less random? It adds determinism to the number; can a > number be more deterministic while still no less random? > > Ah! I know. The answer comes from common sense: > > a = random() # a is definitely a random number > a -= random() # a is no longer random, we subtracted all the randomness from it > > Of course, since number-number => number, a is still a number. And so > we can conclude that adding 1 to a random dice roll does indeed leave > all the randomness still in it. But wait! That means we can do > better!! > > a = random() # a is a random number > a *= 5 # a is clearly five times as random now! > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list It depends if the result (any operation) is in the required range. For example: "int(random.random()+1)" it's not random at all! But "int(random.random()*1000)" my look random if it fits your needs. ;)
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 12:30 +0300 |
| Message-ID | <mailman.2128.1369474230.3114.python-list@python.org> |
| In reply to | #45970 |
lol http://search.dilbert.com/comic/Random%20Nine ---------------------------------------- > Date: Sat, 25 May 2013 19:14:57 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? > From: rosuav@gmail.com > To: python-list@python.org > > On Sat, May 25, 2013 at 7:10 PM, Carlos Nepomuceno > <carlosnepomuceno@outlook.com> wrote: >> ---------------------------------------- >>> 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: rosuav@gmail.com >>> To: python-list@python.org >> [...] >>> 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! ;) > > def random_number(): > return 7 > > ChrisA > -- > http://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-05-25 13:01 +0100 |
| Message-ID | <mailman.2130.1369483263.3114.python-list@python.org> |
| In reply to | #45970 |
On 25/05/2013 09:54, Carlos Nepomuceno wrote: > 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 > In my book this is another fail as lists are inbuilt (yuck!) and so is the add function that'll be called for z+=1. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-05-25 10:03 -0400 |
| Message-ID | <roy-669DAF.10032325052013@news.panix.com> |
| In reply to | #45970 |
In article <74e33270-a79a-4878-a400-8a6cda6637b2@googlegroups.com>, lokeshkoppaka@gmail.com wrote: > 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 A couple of points here: 1) In general, people on mailing lists are not into doing homework problems for other people. 2) If you're going to bring us a homework problem, at least describe the whole problem up front. It really doesn't help to dribble out new requirements one at a time. 3) rustompmody@gmail.com already posted a pointer to the wikipedia article describing the required algorithm in detail. 4) I don't know what "no built-in functions should be used" means. I assume it means, "don't call sort()"? If you can't even call int.__lt__(), it's going to be really hard to do this.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-05-25 10:27 -0400 |
| Message-ID | <mailman.2132.1369492044.3114.python-list@python.org> |
| In reply to | #45992 |
On 05/25/2013 10:03 AM, Roy Smith wrote: > In article <74e33270-a79a-4878-a400-8a6cda6637b2@googlegroups.com>, > lokeshkoppaka@gmail.com wrote: > >> 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 > > A couple of points here: > > 1) In general, people on mailing lists are not into doing homework > problems for other people. > > 2) If you're going to bring us a homework problem, at least describe the > whole problem up front. It really doesn't help to dribble out new > requirements one at a time. > > 3) rustompmody@gmail.com already posted a pointer to the wikipedia > article describing the required algorithm in detail. > > 4) I don't know what "no built-in functions should be used" means. I > assume it means, "don't call sort()"? If you can't even call > int.__lt__(), it's going to be really hard to do this. > The OP has already admitted that he didn't want a sort at all. He wants to COUNT the items, not sort them. So nothing in his orginal post relates to the real homework assignment. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-05-25 14:30 +0000 |
| Message-ID | <51a0cafd$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #45970 |
On Fri, 24 May 2013 23:05:17 -0700, lokeshkoppaka wrote: > On Saturday, May 25, 2013 11:27:38 AM UTC+5:30, Steven D'Aprano wrote: >> 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 The above does not use any built-in functions. > 2. we are expecting a O(n) solution The above is O(n). > 3. Don't use count method The above does not use the count method. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 20:07 +0300 |
| Message-ID | <mailman.2139.1369501676.3114.python-list@python.org> |
| In reply to | #45970 |
---------------------------------------- > To: python-list@python.org > From: breamoreboy@yahoo.co.uk > Subject: Re: help how to sort a list in order of 'n' in python without using inbuilt functions?? > Date: Sat, 25 May 2013 13:01:06 +0100 [...] > In my book this is another fail as lists are inbuilt (yuck!) and so is > the add function that'll be called for z+=1. Indeed! It's a joke Mark! lol ;)
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-25 20:45 +0300 |
| Message-ID | <mailman.2147.1369503942.3114.python-list@python.org> |
| In reply to | #45970 |
---------------------------------------- > 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: lokeshkoppaka@gmail.com [...] > 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 PS: If you find something faster please let me know!
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-05-24 22:43 -0700 |
| Message-ID | <db89bfd0-93bc-4503-874a-dc8383d6cfda@ow4g2000pbc.googlegroups.com> |
| In reply to | #45961 |
On May 25, 10:15 am, lokeshkopp...@gmail.com wrote: > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > 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' Its a classic problem http://en.wikipedia.org/wiki/Dutch_national_flag_problem
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web