Curious behavior of random.shuffle in Sympy Live Shell

13 views
Skip to first unread message

plonter99

unread,
Mar 25, 2017, 5:05:54 PM3/25/17
to sympy
Hi all,
I am new to Sympy.
Going through the tutorial, I tried to do the exercise at http://docs.sympy.org/latest/tutorial/simplification.html#example-continued-fractions
I noticed that the results were not what I expected, so after exploring a little bit, it seems that the following is happening:

>>> import random
>>> l = [1,2,3,4,5]
>>> random.shuffle(l)
>>> l
[5,3,2,4,1]

>>> l
[2,4,1,3,5]

>>> l
[5,3,2,1,4]

>>> l
[3,5,2,4,1]

>>> l
[2,3,4,1,5]


It looks as though l is getting continuously shuffled in-place...

So, my questions are:
  1. What can explain this behavior?
  2. Is this a particular issue with my environment? I am running chrome 49.0.2623.112 on Windows Vista, which is rather old... If it is a general issue then the example in the tutorial doesn't work, unless I missed something...
Thanks!

Aaron Meurer

unread,
Mar 25, 2017, 5:07:29 PM3/25/17
to sy...@googlegroups.com
That's an unfortunate side effect of the way SymPy Live is currently
implemented. It reevaluates expressions every time it executes. In a
real Python shell this would work as expected.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/2b072897-8414-4cd0-99e5-126b6098cf25%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages