A
Andrew Bennetts
A method of every sequence and container on Earth? Eeek.
Like __len__, you mean?
-Andrew.
A method of every sequence and container on Earth? Eeek.
Alex Martelli said:Terry Reedy wrote:
Hmmm, nobody else seemed to have any problem understanding my quip,
for you:including the poster at which it was directed. Let me spell it out
a few people are attacking 'sum' and defending 'reduce'
because the latter is "more general".
So, no, I don't think my idea of "more general" is different from
yours: e.g., a function that, given a sequence, returns its length
AND the number of times 'None' occurs as an item, is more general
than one which just returns the length. That does not make it in
any intrinsic way "necessarily preferable" -- and THAT is my point.
Alex Martelli said:Just replacing the keyword 'lambda' with 'func'? If you were
designing a green-field language, and couldn't find any other way
to express callable literals -- so it only came down to a 2-way
choice between lambda and func as keywords with the same semantics,
I guess I would suggest func as the lesser evil.
How would this notation imply that x is an argument rather than,
say, a global?
The change was that native lists will implement stable sort. My gripe
is that if native lists are required to sort stably and list-alikes
can sort unstably, then list.sort and listalike.sort act differently
in a way that can lead to subtle bugs. ...
It would be icky if some .sort() methods are required to be stable but
others are not.
Note that the most obvious way to implement sort() in C is to call the
standard C library qsort function, which is unstable.
Perhaps my career in statistics and data reduction made reduce() more
immediately obvious to me than some other people.
Donn Cave said:Python may be a hybrid, but certainly none of its parents were FPLs.
Trying to make it one gives both Python and FP a bad name. If you
want a language that really supports both functional and procedural
styles, I think you need Lisp. Look at Dylan, I haven't tried it but
it may be quite a bit more comfortable for Python and C programmers.
Maybe, it's worth to have str(x,8) and str(x,16) instead of oct(x) and hex(x)
and make str() a true inverse function to int()?
I NEVER wondered which of constructions should I
use in any particular case. I just solved the problem and wrote its solution
in that language and the language HELPED me to express myself clearly.
Half of all the conditions in real Python programs are 1 or True.
Andrew Dalke said:Georgy Pruss:Maybe, it's worth to have str(x,8) and str(x,16) instead of oct(x) and hex(x)
and make str() a true inverse function to int()?
What then are the results of
str(30+44j, 16)
str(3.1415926, 8)
str([9, 8, 7], 8)
str("A", 16)
str({"A": 20}, 16)
?
While I, when writing Perl code, also NEVER had a problem. I
ignored just about all of its variations
if ($cond) {$a++}
$a++ if $cond;
$a++ unless !($cond);
unless (!($cond)) {$a++};
I did this not because it was the most expressive but because I wanted to
write code that others could follow, and indeed one of the praises I got was
"wow! It's Perl code I can actually understand!"
...I guess, the same as for
hex(30+44j)
oct(3.1415926)
Ville Vainio said:Lisp is too verbose for my tastes (I don't want to write 'let' ot
'setq'), doesn't have much in the way of libs and generally doesn't
feel as 'right' as Python (I do use Emacs Lisp occasionally,
though.. and will try out some CL one of these days). Dylan, OTOH,
doesn't seem to be all that active a project, at least the last time I
checked.
Andrew said:str(obj, [base=10]) -> converts integer objects (only!) to the given base,
defaults to base 10.
To me, it's very wrong that you can read any radix numbers, but can't
print them. If str(int(s)) == s and int(str(n)) == n (with some limits), I don't
see why str(n,radix) can't be symmetrical to int(s,radix).
BTW there's no symmetry for str() and list()/tuple()/dict() etc.
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.