Favorite non-python language trick?
johng2001 at rediffmail.com
johng2001 at rediffmail.com
Fri Jun 24 18:37:13 EDT 2005
John Machin wrote:
> James wrote:
> > Interesting thread ...
> >
> > 1.) Language support for ranges as in Ada/Pascal/Ruby
> > 1..10 rather than range(1, 10)
>
> Did you mean 1..9 or 1...10 or both or neither?
You are right. There is a difference.
1..10 == range(1, 10 + 1)
> Can this construct be used like this: (i+1)..n ? If not, what would you
> use?
Sure. In Ruby, you can do
i = 2
n = 5
for x in (i+1)..n do
print x
end
Can't in Ada/Pascal as far as I remember.
> What is the frequency of range literals in the average piece of code?
Well! I certainly have not done a study with code metrics. You probably
can find something online. That probably will be variable and might
depend on individual language affordances.
BTW, Ruby's times loop is another thing I find better readable for a
few cases.
4.times {
print "Something ..."
}
than
for x in range(4):
print "Something ..."
More information about the Python-list
mailing list