Re: Tuple question
From: Alex Martelli (aleaxit_at_yahoo.com)
Date: 09/04/04
- Next message: Alex Martelli: "Re: Check existence of members/methods"
- Previous message: Alex Martelli: "Re: Tuple question"
- In reply to: Peter Hansen: "Re: Tuple question"
- Next in thread: Bryan Olson: "Re: Tuple question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 4 Sep 2004 11:00:30 +0200
Peter Hansen <peter@engcorp.com> wrote:
...
> Consider, for example, that one actually has to build the
> tuple in the first place... how can you do that without
> having the info in a list to begin with? (I'm sure there
> are ways if one is ingenious, but I think the answers
> would just go to prove the point I was making.)
tuple(somegenerator(blah)) will work excellently well. In 2.4, you can
even often code that 'somegenerator' inline as a generator
comprehension. So this 'having the info in a list' argument sounds just
totally bogus to me.
Say I want to work with some primes and I have a primes generator.
Primes aren't going to change, so a tuple is a natural. I start with,
e.g.,
ps = tuple(itertools.islice(primes(), 999999))
...and then I'm stumped because I can't index into ps to find, say, the
progressive number of some given prime N by ps.index(N). How silly,
having to keep ps a list, i.e. mutable (when it intrinsically isn't)
just to be able to index into it! [I can usefully exploit ps's
sortedness via module bisect... ignoring the latter's specs and docs
that keep screamign LISTS, bisect.bisect DOES work on tuples... but I
wouldn't feel comfy about that surviving, given said docs and
specs...:-)
Alex
- Next message: Alex Martelli: "Re: Check existence of members/methods"
- Previous message: Alex Martelli: "Re: Tuple question"
- In reply to: Peter Hansen: "Re: Tuple question"
- Next in thread: Bryan Olson: "Re: Tuple question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|