On Fri, Sep 19, 2008 at 9:51 PM, Steven D'Aprano
[EMAIL PROTECTED] wrote:
Extending len() to support iterables sounds like a good idea, except that
it's not.
Here are two iterables:
def yes(): # like the Unix yes command
while True:
yield y
def rand(total):
Return random
Steven D'Aprano:
Extending len() to support iterables sounds like a good idea, except that it's
not.
Python language lately has shifted toward more and more usage of lazy
iterables (see range lazy by default, etc). So they are now quite
common. So extending len() to make it act like leniter()
On Mon, 22 Sep 2008 04:21:12 -0700, bearophileHUGS wrote:
Steven D'Aprano:
Extending len() to support iterables sounds like a good idea, except
that it's not.
Python language lately has shifted toward more and more usage of lazy
iterables (see range lazy by default, etc). So they are now
Steven D'Aprano:
I'm sorry, I don't recognise leniter(). Did I miss something?
I have removed the docstring/doctests:
def leniter(iterator):
if hasattr(iterator, __len__):
return len(iterator)
nelements = 0
for _ in iterator:
nelements += 1
return nelements
it
Simon Mullis [EMAIL PROTECTED] writes:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
...
dict_of_counts = dict([(v[0:3], count) for v in l])
Untested:
def major_version(version_string):
convert '1.2.3.2' to '1.2'
return '.'.join(version_string.split('.')[:2])
Gerard flanagan wrote:
George Sakkis wrote:
..
Note that this works correctly only if the versions are already sorted
by major version.
Yes, I should have mentioned it. Here's a fuller example below. There's
maybe better ways of sorting version numbers, but this is what I do.
Indeed,
Boris Borcic wrote:
Gerard flanagan wrote:
George Sakkis wrote:
..
Note that this works correctly only if the versions are already sorted
by major version.
Yes, I should have mentioned it. Here's a fuller example below.
There's maybe better ways of sorting version numbers, but this is
Gerard flanagan:
data.sort()
datadict = \
dict((k, len(list(g))) for k,g in groupby(data, lambda s:
'.'.join(s.split('.',2)[:2])))
That code may run correctly, but it's quite unreadable, while good
Python programmers value high readability. So the right thing to do is
to split that line
On Sep 19, 2:01 pm, [EMAIL PROTECTED] wrote:
Gerard flanagan:
data.sort()
datadict = \
dict((k, len(list(g))) for k,g in groupby(data, lambda s:
'.'.join(s.split('.',2)[:2])))
That code may run correctly, but it's quite unreadable, while good
Python programmers value high
On Fri, 19 Sep 2008 17:00:56 -0700, MRAB wrote:
Extending len() to support iterables sounds like a good idea, except
that it could be misleading when:
len(file(path))
returns the number of lines and /not/ the length in bytes as you might
first think!
Extending len() to support
MRAB:
except that it could be misleading when:
len(file(path))
returns the number of lines and /not/ the length in bytes as you might
first think! :-)
Well, file(...) returns an iterable of lines, so its len is the number
of lines :-)
I think I am able to always remember this fact.
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version : count.
(So, in this case:
dict_of_counts = { 1.1 : 1,
1.2 : 2,
Simon Mullis napisał(a):
Something like:
dict_of_counts = dict([(v[0:3], count) for v in l])
I can't seem to figure out how to get count, as I cannot do x += 1
or x++ as x may or may not yet exist, and I haven't found a way to
create default values.
It seems to me that the count you're
On Sep 18, 10:54 am, Simon Mullis [EMAIL PROTECTED] wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version : count.
(So, in this case:
On Sep 18, 10:54 am, Simon Mullis [EMAIL PROTECTED] wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version : count.
(So, in this case:
Simon Mullis wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version : count.
(So, in this case:
dict_of_counts = { 1.1 : 1,
On Sep 18, 10:54 am, Simon Mullis [EMAIL PROTECTED] wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version : count.
(So, in this case:
On Sep 18, 11:43 am, Gerard flanagan [EMAIL PROTECTED] wrote:
Simon Mullis wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with major_version :
Haha!
Thanks for all of the suggestions... (I love this list!)
SM
2008/9/18 [EMAIL PROTECTED]:
On Sep 18, 10:54 am, Simon Mullis [EMAIL PROTECTED] wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3,
George Sakkis wrote:
On Sep 18, 11:43 am, Gerard flanagan [EMAIL PROTECTED] wrote:
Simon Mullis wrote:
Hi,
Let's say I have an arbitrary list of minor software versions of an
imaginary software product:
l = [ 1.1.1.1, 1.2.2.2, 1.2.2.3, 1.3.1.2, 1.3.4.5]
I'd like to create a dict with
20 matches
Mail list logo