On 6/28/07, Hamptonio <[EMAIL PROTECTED]> wrote:
> Whoops! - sorry about the misreporting on the GF(5) behavior. I was
> playing around with lots of similar versions and I must have gotten
> confused.
>
> That extra loop you deleted was put in to avoid errors on weird cases
> like: flatten([[]]),
Whoops! - sorry about the misreporting on the GF(5) behavior. I was
playing around with lots of similar versions and I must have gotten
confused.
That extra loop you deleted was put in to avoid errors on weird cases
like: flatten([[]]), which gives an "IndexError: list index out of
range" if the
> I've incorporated this into SAGE as a patch.
I like the final form.
> [EMAIL PROTECTED]:~/d/sage/sage/misc$ hg export 5194
> # HG changeset patch
> # User William Stein <[EMAIL PROTECTED]>
> # Date 1183076918 25200
> # Node ID 25f23d18288895f46a6aaa2bd8ef147cde5e31f3
> # Parent 65b460226d81
On 6/28/07, Hamptonio <[EMAIL PROTECTED]> wrote:
> Interesting. I think I originally ripped mine off from one of [...]
Hi,
I've incorporated this into SAGE as a patch. The main things I did
were add more examples and delete part of the function which I
consider stupid. E.g., you wrote "flatten
Interesting. I think I originally ripped mine off from one of the
comments at:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051
although I've tried to make mine more readable.
The thread you linked to has the apparent winner of Ron Adams:
def flatten(seq):
s = []
while
There's a good discussion on the python mailing list regarding flatten:
http://mail.python.org/pipermail/python-list/2005-July/330367.html
particularly, it's got a number of different implementations, and benchmarks.
On Thu, 28 Jun 2007, Hamptonio wrote:
>
> I often want to flatten nested lis
To be honest I didn't give it much thought. This is modified from the
simplest code I could find that did the job.
flatten(GF(5)) does return [0,1,2,3,4], while flatten([GF(5)]) returns
[Finite Field of size 5]. However, you can do:
flatten([GF(5)],ltypes = (list, tuple,
sage.rings.finite_fiel
> def flatten(in_list, ltypes=(list, tuple)):
> ...
> ltypes -- optional list of particular types to flatten
Could you elaborate on the decisions made around iterators here? I
can see that flatten([GF(5)]) could be tricky -- is it [GF(5)] or [0,
1, 2, 3, 4]?
Nick
--~--~-~--~---