On 9/25/2017 5:37 PM, Thomas Jollans wrote:
On 25/09/17 18:44, john polo wrote:
Python List,
I am trying to make practice data for plotting purposes. I am using
Python 3.6. The instructions I have are
import matplotlib.pyplot as plt
import math
import numpy as np
t = np.arange(0, 2.5, 0.1)
y1
his:
t = np.arange(0, 2.5, 0.1)
y1 = np.sin(np.pi * t)
Without using numpy at all, this might be
t = [i * 0.1 for i in range(25)]
y1 = [math.pi * a for a in t]
> plt.plot(t,y1)
>
> However, at this point, I get a TypeError that says
>
> object of type 'map' has no len(
On 9/25/2017 12:03 PM, Paul Moore wrote:
You're using Python 3, and I suspect that you're working from
instructions that assume Python 2. In Python 3, the result of map() is
a generator, not a list (which is what Python 2's map returned). In
order to get an actual list (which appears to be what y
, math.pi*t)
> plt.plot(t,y1)
>
> However, at this point, I get a TypeError that says
>
> object of type 'map' has no len()
>
> In [6]: t
> Out[6]:
> array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ,
> 1.1, 1.2, 1.3, 1.4, 1.5,
; y1 = map(math.sin, math.pi*t)
> plt.plot(t,y1)
>
> However, at this point, I get a TypeError that says
>
> object of type 'map' has no len()
you probably need to convert y1 from a 'map' object (a type of an
iterator) to an array.
y1 = map(ma
in, math.pi*t)
> plt.plot(t,y1)
>
> However, at this point, I get a TypeError that says
>
> object of type 'map' has no len()
>
> In [6]: t
> Out[6]:
> array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ,
> 1.1, 1.2, 1.3, 1.4, 1.5
)
However, at this point, I get a TypeError that says
object of type 'map' has no len()
In [6]: t
Out[6]:
array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ,
1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1,
2.2, 2.3, 2.4])
In [7]: y1
O
y1 = list(map(math.sin, math.pi*t))
or
y1 = tuple(map(math.sin, math.pi*t))
(Does not make much difference.)
plt.plot(t,y1)
or
plt.plot(t, list(y1))
However, at this point, I get a TypeError that says
object of type 'map' has no len()
In 3.x, map returns an iterator. plot needs
TypeError that says
object of type 'map' has no len()
In [6]: t
Out[6]:
array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ,
1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1,
2.2, 2.3, 2.4])
In [7]: y1
Out[7]:
In [8]: math.pi*t
Out[8]:
On Mon, Dec 5, 2016 at 6:14 AM, Terry Reedy wrote:
> On 12/3/2016 7:31 PM, Chris Angelico wrote:
>>
>> On Sun, Dec 4, 2016 at 11:10 AM, Terry Reedy wrote:
But the expression result isn't even used. So this is better written:
>>>
>>>
>>> matplotlib.pyplot.xlabel sets x-axis scaling, with
On 12/3/2016 7:31 PM, Chris Angelico wrote:
On Sun, Dec 4, 2016 at 11:10 AM, Terry Reedy wrote:
But the expression result isn't even used. So this is better written:
matplotlib.pyplot.xlabel sets x-axis scaling, with no documented return
value.
http://matplotlib.org/api/pyplot_api.html#matplo
On Sun, Dec 4, 2016 at 11:10 AM, Terry Reedy wrote:
>> But the expression result isn't even used. So this is better written:
>
>
> matplotlib.pyplot.xlabel sets x-axis scaling, with no documented return
> value.
> http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel
> If, as seems re
if k in [0, len(n_trials) - 1] else None
The backslash means "this continues on the next line".
> The ternary conditional looks like this:
5 if 1 < 2 else 7
Since 1 < 2, this has the value of 5. If not, it would have the value 7.
But the expression result isn'
On 2016-12-03 23:11, Robert wrote:
On Saturday, December 3, 2016 at 6:09:02 PM UTC-5, Robert wrote:
Hi,
I am trying to understand the meaning of the below code snippet. Though I have
a Python IDLE at computer, I can't get a way to know below line:
if k in [0, len(n_trials) - 1] else No
On Sun, Dec 4, 2016 at 10:11 AM, Robert wrote:
> I just notice that there is a slash character (\) before the if line.
> What is it for?
Yes, that's important. The entire line of code is:
plt.xlabel("$p$, probability of heads") \
if k in [0, len(n_trials
On Saturday, December 3, 2016 at 6:09:02 PM UTC-5, Robert wrote:
> Hi,
>
> I am trying to understand the meaning of the below code snippet. Though I have
> a Python IDLE at computer, I can't get a way to know below line:
>
> if k in [0, len(n_trials) - 1] else None
>
Hi,
I am trying to understand the meaning of the below code snippet. Though I have
a Python IDLE at computer, I can't get a way to know below line:
if k in [0, len(n_trials) - 1] else None
I feel it is strange for what returns when the 'if' condition is true?
The second part
,'norm')
>
>
>
> # I then get the following error:
>
>
>
> File "", line 1, in
>
> File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py",
> line 3413, in kstest
>
> N = len(vals)
>
> TypeEr
t;", line 1, in
> File
> "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py",
> line 3413, in kstest
> N = len(vals)
> TypeError: len() of unsized object
>
> Any ideas on why this isn't working would be great.
My guess is
t;, line 1, in
File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line
3413, in kstest
N = len(vals)
TypeError: len() of unsized object
Any ideas on why this isn't working would be great.
--
https://mail.python.org/mailman/listinfo/python-list
r')
# The string is simply a 1D array
# Then performing the ks test:
kstest(control,'norm')
# I then get the following error:
File "", line 1, in
File "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py", line
3413, in kstest
N = len(vals)
Ty
ndarrays work. Essentially
>len and iter treat the array as if it were a list of lists (of lists
>...).
--
http://mail.python.org/mailman/listinfo/python-list
On 8 February 2013 06:24, Demian Brecht wrote:
> On 2013-02-07 8:30 PM, "Terry Reedy" wrote:
>
> If a memoryview (3+) is representing a non-continuguous block of memory (>
> 1
> ndim), will len(obj) not return incorrect results? It seems to be
> reporting the sha
figured I'd write something about my findings as I dug around the source
in order to answer the question for myself.
Still wondering about memoryview though:
If a memoryview (3+) is representing a non-continuguous block of memory (>
1
ndim), will len(obj) not return incorrect results? It
On 2/7/2013 8:09 PM, Demian Brecht wrote:
http://demianbrecht.github.com/posts/2013/02/07/understanding-len/
When len() is called passing an immutable built-in type (such as a
string), I'd assume that the overhead in doing so is simply a function
call and there are no on-call calcula
tions.
http://demianbrecht.github.com/posts/2013/02/07/understanding-len/
However, my research brought up a question (I'm assuming someone here can
answer this):
If a memoryview is representing a non-continuguous block of memory (> 1
ndim), will len(obj) not return incorrect results? I
On 10/18/2012 2:42 PM, Demian Brecht wrote:
Awesome. Pretty much what I figured. Of course, I'll have to dig around
the source just to confirm this with my own eyes (more just curiosity
than anything),
If you do, please followup with a report.
--
Terry Jan Reedy
--
http://mail.python.org/mai
On 10/18/2012 3:18 PM, Prasad, Ramit wrote:
Terry Reedy wrote:
On 10/18/2012 1:23 PM, Demian Brecht wrote:
When len() is called passing an immutable built-in type (such as a
string), I'd assume that the overhead in doing so is simply a function
call and there are no on-call calculations
On Thu, Oct 18, 2012 at 12:43 PM, Daniel Urban wrote:
> The source is usually in Objects/*object.c (e.g., the source for list
> is in Objects/listobject.c, dict is in dictobject.c and so on). The
> implementation of __len__ is usually in a method called
> whatever_length (e.g., dict.__len__ is cal
Ian Kelly wrote:
> Sent: Thursday, October 18, 2012 2:39 PM
> To: Python
> Subject: Re: len() on mutables vs. immutables
>
> On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit
> wrote:
> > Why does pointer arithmetic work for dicts? I would think the position
> > of
On Thu, Oct 18, 2012 at 8:42 PM, Demian Brecht wrote:
>> str, bytes, bytearrays, arrays, sets, frozensets, dicts, dictviews, and
>> ranges should all return len in O(1) time. That includes the possibility
>> of a subtraction as indicated above.
>
> Awesome. Pretty much w
On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit
wrote:
> Why does pointer arithmetic work for dicts? I would think the position
> of a value would be based on the hash of the key and thus "random" for
> the context of this conversation.
It doesn't. len() on CPython dicts
Terry Reedy wrote:
> On 10/18/2012 1:23 PM, Demian Brecht wrote:
>
> > When len() is called passing an immutable built-in type (such as a
> > string), I'd assume that the overhead in doing so is simply a function
> > call and there are no on-call calculations done. Is
into Python (well,
> CPython at this point anyway).
>
> When len() is called passing an immutable built-in type (such as a
> string), I'd assume that the overhead in doing so is simply a function
> call and there are no on-call calculations done. Is that correct?
>
> I
n most dynamic cases
(obviously totally depends on implementation details).
> str, bytes, bytearrays, arrays, sets, frozensets, dicts, dictviews, and
> ranges should all return len in O(1) time. That includes the possibility
> of a subtraction as indicated above.
Awesome. Pretty much wha
On 10/18/2012 11:28 AM, Nick Cash wrote:
It appears that list has len() complexity of O(1)
source: http://wiki.python.org/moin/TimeComplexity
It may be worth mentioning that lists in Python are implemented using arrays
instead of linked lists.
It's reasonable to assume that other bui
On 10/18/2012 1:23 PM, Demian Brecht wrote:
When len() is called passing an immutable built-in type (such as a
string), I'd assume that the overhead in doing so is simply a function
call and there are no on-call calculations done. Is that correct?
See below.
I'd also assume th
l,
CPython at this point anyway).
When len() is called passing an immutable built-in type (such as a
string), I'd assume that the overhead in doing so is simply a function
call and there are no on-call calculations done. Is that correct?
I'd also assume that mutable built-in types
Thanks Chris & Christian.
Mistery solved :)
Ernest
--
http://mail.python.org/mailman/listinfo/python-list
> And yet, p.__len__() returns 3. I though len(object) simply
> called object.__len__.
Not exactly, all __magic__ methods of new style classes are called like
getattr(type(obj), "__len__")(obj). As a result magic methods are never
looked up on the object, including hooks like
else:
> return str(self).__getattribute__(name)
> def write(self, data):
> self.content.append(data)
>
> Then I do:
>
> In [50]: p = Part()
>
> In [51]: p.write('foo')
>
> However, len(p) fails:
>
> TypeError: object of type 'P
ta)
Then I do:
In [50]: p = Part()
In [51]: p.write('foo')
In [52]: p.upper()
Out[56]: 'FOO'
This is okay, works as expected.
However, len(p) fails:
TypeError: object of type 'Part' has no len()
And yet, p.__len__() returns 3. I though len(object) simply
called o
; Now I'm often what to do something if I've more than 1 element in the result.
>> So I test:
>>
>>if len ( Result ) > 1 :
>>
>> But to prevent exceptions, i've to write ( I often forget)
>> if Result and ( len ( Result ) > 1 ) :
>&
Please pardon me for breaking threading, but Stef's original post has not
come through to me.
On 6/30/10 11:39 AM, Stef Mientki wrote:
> hello,
>
> I've lot of functions that returns their result in some kind of tuple /
> list / array,
> and if there is no result, these functions return None.
I test:
which works fine if beforehand you do
Result = presumedFuncCall() or []
particularly if you want to test len subsequently.
Emile
if len ( Result )> 1 :
But to prevent exceptions, i've to write ( I often forget)
if Result and ( len ( Result )> 1 ) :
So I wonder
On Wed, Jun 30, 2010 at 12:39 PM, Stef Mientki wrote:
> So I wonder why len is not allowed on None
> and if there are objections to extend the len function .
For the same reason that (None + 42) doesn't return 42, and that
(None.upper()) doesn't return NONE.
--
http://mail.py
the
result.
So I test:
if len ( Result ) > 1 :
But to prevent exceptions, i've to write ( I often forget)
if Result and ( len ( Result ) > 1 ) :
Just do:
if Result:
You don't have to do a length check > 1; because if Result has a
length of 0, it'll be false too. S
On 6/30/10 12:02 PM, Tim Chase wrote:
On 06/30/2010 01:50 PM, Stephen Hansen wrote:
On 6/30/10 11:39 AM, Stef Mientki wrote:
if len ( Result )> 1 :
But to prevent exceptions, i've to write ( I often forget)
if Result and ( len ( Result )> 1 ) :
Just do:
if Result:
You don
On 06/30/2010 01:50 PM, Stephen Hansen wrote:
On 6/30/10 11:39 AM, Stef Mientki wrote:
if len ( Result )> 1 :
But to prevent exceptions, i've to write ( I often forget)
if Result and ( len ( Result )> 1 ) :
Just do:
if Result:
You don't have to do a length check
Stef Mientki, 30.06.2010 20:39:
I've lot of functions that returns their result in some kind of tuple / list /
array,
and if there is no result, these functions return None.
Now I'm often what to do something if I've more than 1 element in the result.
So I test:
if len
I test:
if len ( Result ) > 1 :
But to prevent exceptions, i've to write ( I often forget)
if Result and ( len ( Result ) > 1 ) :
So I wonder why len is not allowed on None
and if there are objections to extend the len function .
thanks,
Stef Mientki
Because the natural interp
re than 1 element in the
> result.
> So I test:
>
>if len ( Result ) > 1 :
>
> But to prevent exceptions, i've to write ( I often forget)
> if Result and ( len ( Result ) > 1 ) :
>
use
if Result:
Checking the length would be a bad idea.
--
http://mail.python.org/mailman/listinfo/python-list
On 6/30/10 11:39 AM, Stef Mientki wrote:
hello,
I've lot of functions that returns their result in some kind of tuple /
list / array,
and if there is no result, these functions return None.
Now I'm often what to do something if I've more than 1 element in the
result.
So
hello,
I've lot of functions that returns their result in some kind of tuple / list /
array,
and if there is no result, these functions return None.
Now I'm often what to do something if I've more than 1 element in the result.
So I test:
if len ( Result ) > 1 :
But to
e, btw, will
demote a two-dimensional 1x1 matrix to a scalar for Matrix multiplication,
which may hide errors)
If you are converting from matlab, I'd say you have biggest things to worry
about. As you said, you can just replace the len function (even safer may be
to do [1]). Assignment, fo
"Dr. Phillip M. Feldman" wrote in message
news:mailman.3699.1248490256.8015.python-l...@python.org...
> Here's a simple-minded example:
...
> This function works fine if xs is a list of floats, but not if it is single
> float. It can be made to work as follows:
Wow, you could substitute "Matlab
On 2009-07-27, Joshua Kugler wrote:
> Dr. Phillip M. Feldman wrote:
>
>> "As far as I know, there is no programming language which
>> treats scalars like ints as if they were vectors of length 1"
>>
>> Actually, Matlab does:
>>
length(5)
>> ans =
>> 1
>
> Oddly enough, so does Pe
Dr. Phillip M. Feldman wrote:
>
> "As far as I know, there is no programming language which treats scalars
> like ints as if they were
> vectors of length 1"
>
> Actually, Matlab does:
>
>>> length(5)
> ans =
> 1
>>>
Oddly enough, so does Perl:
$ print length(44)
2
(that's in the Zoidb
To the best of my recollection, the len() function only applies to
container objects; i. e. tuples, lists, strings, etc. an integer
object is not a container, thus one receives an error when sending an
int as an argument for len().
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
I'm curious what those applications are, because regular multiplication
behaves differently depending on whether you have a 1x1 matrix or a
scalar:
[[2]]*[[1, 2, 3], [2, 3, 4]] is not defined
2*[[1, 2, 3], [2, 3, 4]] = [[2, 4, 6], [2, 6, 8]]
I'm curious as to what thes
On Sat, 25 Jul 2009 16:21:39 -0700, Erik Max Francis wrote:
> Steven D'Aprano wrote:
>> But it's not "practically every function". It's hardly any function at
>> all -- in my code, I don't think I've ever wanted this behavior. I
>> would consider it an error for function(42) and function([42]) to
; the expectation of the coder. I say "reasonably", because if
> >> you allow SD> unreasonable situations, everything is "ambiguous":
> >
> > That's for me the reason that len(42) is ambiguous. The OP apparently
> > had 1 as expectation, whereas m
On Sat, Jul 25, 2009 at 6:47 PM, Erik Max Francis wrote:
> Chris Rebert wrote:
>>
>> On Sat, Jul 25, 2009 at 4:21 PM, Erik Max Francis wrote:
>>>
>>> Steven D'Aprano wrote:
But it's not "practically every function". It's hardly any function at
all
-- in my code, I don't think I'
Chris Rebert wrote:
On Sat, Jul 25, 2009 at 4:21 PM, Erik Max Francis wrote:
Steven D'Aprano wrote:
But it's not "practically every function". It's hardly any function at all
-- in my code, I don't think I've ever wanted this behavior. I would
consider it an error for function(42) and function(
On Sat, Jul 25, 2009 at 4:21 PM, Erik Max Francis wrote:
> Steven D'Aprano wrote:
>>
>> But it's not "practically every function". It's hardly any function at all
>> -- in my code, I don't think I've ever wanted this behavior. I would
>> consider it an error for function(42) and function([42]) to b
Steven D'Aprano wrote:
But it's not "practically every function". It's hardly any function at
all -- in my code, I don't think I've ever wanted this behavior. I would
consider it an error for function(42) and function([42]) to behave the
same way. One is a scalar, and the other is a vector -- t
is "ambiguous":
That's for me the reason that len(42) is ambiguous. The OP apparently
had 1 as expectation, whereas my first thought was the minimal number of
bits to represent the number and 7.5 million came later :=). The number
of bits I certainly find reasonable, and I would fi
):
if isinstance(xs,(int,float,complex)): xs= [xs]
for x in xs:
print x
Having to put such extra logic into practically every function is one
of the
annoying things about Python.
And where comes "len(xs)" into play here? What you want is iteration
over scalars.
He explained in another post
On 2009-07-24 21:50, Dr. Phillip M. Feldman wrote:
Here's a simple-minded example:
def dumbfunc(xs):
for x in xs:
print x
This function works fine if xs is a list of floats, but not if it is single
float. It can be made to work as follows:
def dumbfunc(xs):
if isinstance(xs,(in
On Sat, 25 Jul 2009 03:50:54 +0100, Dr. Phillip M. Feldman
wrote:
Here's a simple-minded example:
def dumbfunc(xs):
for x in xs:
print x
This function works fine if xs is a list of floats, but not if it is
single
float. It can be made to work as follows:
def dumbfunc(xs):
On Saturday 25 July 2009 14:59:43 Steven D'Aprano wrote:
> On Sat, 25 Jul 2009 10:03:58 +0200, Piet van Oostrum wrote:
> >>S> And there's nothing ambiguous about len(42).
> >
> > len(42) should be 7.5 million.
>
> And "I don't understand you
>>>>> Steven D'Aprano (SD) wrote:
>SD> Ambiguity essentially boils down to being unable to reasonably predict
>SD> the expectation of the coder. I say "reasonably", because if you allow
>SD> unreasonable situations, everything is "ambiguous&
On Sat, 25 Jul 2009 10:03:58 +0200, Piet van Oostrum wrote:
>>S> And there's nothing ambiguous about len(42).
>
> len(42) should be 7.5 million.
And "I don't understand your reasoning".upper() should be "Millennium
Hand and Shrimp!".
Every
On 7/25/2009 5:34 AM, Hendrik van Rooyen wrote:
On Friday 24 July 2009 22:09:15 Marcus Wanner wrote:
First one to correctly decompress the value 0 into an ASCII character
wins the title of the world's most capable hacker :p
that is easy.
the xor of 0 and 1 is 1, which is ASCII soh, if I reme
On Friday 24 July 2009 22:09:15 Marcus Wanner wrote:
> First one to correctly decompress the value 0 into an ASCII character
> wins the title of the world's most capable hacker :p
that is easy.
the xor of 0 and 1 is 1, which is ASCII soh, if I remember right.
soh is start of header.
Burroughs
On Friday 24 July 2009 21:04:55 Roy Smith wrote:
> Compressing strings to a single bit is easy. It's the uncompressing that's
> tricky.
Not really - all you have to do is to apply the EXACT same sequence
of operations that compressed it, in reverse.
The unfortunate part is that this informatio
>>>>> Steven D'Aprano (S) wrote:
>S> Chris, I'm curious why you think that these Zen are relevant to the OP's
>S> complaint.
>S> Re explicit vs implicit, len(42) is just as explicit as len([42, 23]).
>S> Arguably (I wouldn't argue th
): xs= [xs]
for x in xs:
print x
Having to put such extra logic into practically every function is one of the
annoying things about Python.
And where comes "len(xs)" into play here? What you want is iteration
over scalars.
I do think that if you frequently have to write code
On Jul 23, 11:35 pm, "Dr. Phillip M. Feldman"
wrote:
> Some aspects of the Python design are remarkably clever, while others leave
> me perplexed. Here's an example of the latter: Why does len() give an error
> when applied to an int or float? len() should always return so
On Friday 24 July 2009 16:45:40 Mark Dickinson wrote:
> On Jul 24, 3:11 pm, "Rhodri James"
>
> wrote:
> > Which doesn't make your point less valid. In fact I'd go so
> > far as to argue that what len() gives you is the number of
> > items in a co
u can now easily get the behaviour you
want with a single extra line per function:
>>> @matlab
... def mean(numbers):
... return sum(numbers)/len(numbers)
...
>>> mean([4.5])
4.5
>>> mean(4.5)
4.5
>>> mean([4.5, 3.6])
4.0498
Decorators are extr
On Sat, Jul 25, 2009 at 4:50 AM, Dr. Phillip M.
Feldman wrote:
>
> Here's a simple-minded example:
>
> def dumbfunc(xs):
> for x in xs:
> print x
>
> This function works fine if xs is a list of floats, but not if it is single
> float. It can be made to work as follows:
>
> def dumbfunc(xs):
On Jul 24, 6:57 am, Grant Edwards wrote:
> On 2009-07-24, Dr. Phillip M. Feldman wrote:
>
>
>
> > Some aspects of the Python design are remarkably clever, while
> > others leave me perplexed. Here's an example of the latter:
> > Why does len() give an er
On Fri, Jul 24, 2009 at 7:50 PM, Dr. Phillip M.
Feldman wrote:
>
> Here's a simple-minded example:
>
> def dumbfunc(xs):
> for x in xs:
> print x
>
> This function works fine if xs is a list of floats, but not if it is single
> float. It can be made to work as follows:
>
> def dumbfunc(xs):
;> me perplexed. Here's an example of the latter: Why does len() give an
>> error
>> when applied to an int or float? len() should always return something; in
>> particular, when applied to a scalar, it should return a value of 1. Of
>> course, I can define my own function
"As far as I know, there is no programming language which treats scalars like
ints as if they were
vectors of length 1"
Actually, Matlab does:
>> length(5)
ans =
1
>>
--
View this message in context:
http://www.nabble.com/len%28%29-should-always-return-somethi
isinstance(x, (int, float, complex))
is certainly very compact, and does what I want. Thanks!
--
View this message in context:
http://www.nabble.com/len%28%29-should-always-return-something-tp24639361p24654347.html
Sent from the Python - python-list mailing list archive at Nabble.com
"Dr. Phillip M. Feldman" wrote in message
news:mailman.3644.1248417347.8015.python-l...@python.org...
Some aspects of the Python design are remarkably clever, while others
leave
me perplexed. Here's an example of the latter: Why does len() give an
error
when applied to an in
Roy Smith wrote:
> In article ,
> Terry Reedy wrote:
>
>> Better:if isinstance(x, (int, float, complex)):
>
> I never noticed this before, but it seems odd that the second argument
> to isinstance() should be a tuple. Using the normal arguments made
> about tuples vs. lists, it seems lik
Chris Rebert wrote:
I think the point made by Grant Edwards is instructive. len(x) = 1
typically implies list(x)[0] and similar should be valid.
At least, one should be able to iterate with x and get len(x) items.
See below.
And there's nothing ambiguous about len(42).
Really? Wh
Steven D'Aprano wrote:
On Fri, 24 Jul 2009 15:03:29 -0400, Roy Smith wrote:
In article ,
Terry Reedy wrote:
Better:if isinstance(x, (int, float, complex)):
I never noticed this before, but it seems odd that the second argument
to isinstance() should be a tuple. Using the normal argume
On Fri, Jul 24, 2009 at 1:30 PM, Tim Chase wrote:
> Marcus Wanner wrote:
>>
>> First one to correctly decompress the value 0 into an ASCII
>> character wins the title of the world's most capable hacker :p
>
> Bah...uncompressing the value 0 into *an* ASCII character is easy.
> Uncompressing it int
Marcus Wanner wrote:
First one to correctly decompress the value 0 into an ASCII
character wins the title of the world's most capable hacker :p
Bah...uncompressing the value 0 into *an* ASCII character is
easy. Uncompressing it into the *original* ASCII character from
which it was compressed
On 7/24/2009 4:18 PM, Mark Lawrence wrote:
Marcus Wanner wrote:
On 7/24/2009 3:04 PM, Roy Smith wrote:
In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:
Nah. 7 contains three bits, so le
Marcus Wanner wrote:
On 7/24/2009 3:04 PM, Roy Smith wrote:
In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:
Nah. 7 contains three bits, so len(7) should *clearly* return 3.
and len("7
On 7/24/2009 3:04 PM, Roy Smith wrote:
In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:
Nah. 7 contains three bits, so len(7) should *clearly* return 3.
and len("7") must return
others
>>> leave me perplexed. Here's an example of the latter: Why does len()
>>> give an error when applied to an int or float? len() should always
>>> return something; in particular, when applied to a scalar, it should
>>> return a value of 1. Of course,
On Fri, 24 Jul 2009 15:03:29 -0400, Roy Smith wrote:
> In article ,
> Terry Reedy wrote:
>
>> Better:if isinstance(x, (int, float, complex)):
>
> I never noticed this before, but it seems odd that the second argument
> to isinstance() should be a tuple. Using the normal arguments made
> a
On Fri, 24 Jul 2009 00:02:28 -0700, Chris Rebert wrote:
> On Thu, Jul 23, 2009 at 11:35 PM, Dr. Phillip M.
> Feldman wrote:
>>
>> Some aspects of the Python design are remarkably clever, while others
>> leave me perplexed. Here's an example of the latter: Why doe
In article <0279f596$0$5185$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
> On Fri, 24 Jul 2009 16:50:03 +0200, superpollo wrote:
>
> >> Nah. 7 contains three bits, so len(7) should *clearly* return 3.
> >
> > and len("7") must return 8,
1 - 100 of 216 matches
Mail list logo