On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote:
> Sorry for late reply, I somehow missed this email.
>
> On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote:
> > The reason I ask: I sorely miss haskell's pattern matching in python.
> >
> > It goes some way:
> >
> ((x
On Friday, February 6, 2015 at 6:40:23 PM UTC+5:30, Devin Jeanpierre wrote:
> Sorry for late reply, I somehow missed this email.
>
> On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote:
> > The reason I ask: I sorely miss haskell's pattern matching in python.
> >
> > It goes some way:
> >
> ((x
Sorry for late reply, I somehow missed this email.
On Thu, Feb 5, 2015 at 8:59 AM, Rustom Mody wrote:
> The reason I ask: I sorely miss haskell's pattern matching in python.
>
> It goes some way:
>
((x,y),z) = ((1,2),3)
x,y,z
> (1, 2, 3)
>
> But not as far as I would like:
>
((x,y)
Chris Angelico wrote:
[] = x
# is equivalent to
try: next(iter(x))
except StopIteration: pass
else: raise ValueError("too many values to unpack (expected 0)")
It's a way of asserting that an iterator is exhausted!
But why disallow using () for the same thing? This
is a blatant case of outright
On Fri, Feb 6, 2015 at 12:12 PM, Devin Jeanpierre
wrote:
> Here's another example, one that still exists in Python 3:
>
[] = ''
() = ''
> File "", line 1
> SyntaxError: can't assign to ()
>
> The syntax explicitly blacklists (), but forgets to blacklist [].
So... this is actually a re
On Thu, Feb 5, 2015 at 8:08 AM, Ian Kelly wrote:
> On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano
> wrote:
>> Devin Jeanpierre wrote:
>>> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
[result] = f()
result
> 42
Huh, was not aware of that alternate syntax.
Devin Jeanpierre wrote:
On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote:
[result] = f()
result
Huh, was not aware of that alternate syntax.
Nor are most people. Nor is Python, in some places -- it seems like
peop
On 2015-02-05 09:08, Ian Kelly wrote:
> > Got an example where you can use a,b but not [a,b] or (a,b)?
>
> >>> def f(a, (b, c)):
> ... print a, b, c
> ...
Interesting. I knew that at one point you could do this with lambdas
but never thought to do it with regular functions. There are ti
On Thursday, February 5, 2015 at 10:15:29 PM UTC+5:30, Rustom Mody wrote:
> On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote:
> > On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote:
> > > Devin Jeanpierre wrote:
> > >
> > >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
>
On 2015-02-05 08:45, Rustom Mody wrote:
> > >>> def f(a, (b, c)):
> > ... print a, b, c
>
> What the hell is that?!
> First I am hearing/seeing it.
> Whats it called?
"tuple parameter unpacking", removed in Py3
https://www.python.org/dev/peps/pep-3113/
-tkc
--
https://mail.python.org/ma
Tuple packing. No longer supported in Python 3, but in available in Python <= 2.
Skip
On Thu, Feb 5, 2015 at 10:45 AM, Rustom Mody wrote:
> On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote:
>> On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote:
>> > Devin Jeanpierre wrote:
>>
On Thursday, February 5, 2015 at 9:39:27 PM UTC+5:30, Ian wrote:
> On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano wrote:
> > Devin Jeanpierre wrote:
> >
> >> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
> >>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten wrote:
> Another alternative i
On Thu, Feb 5, 2015 at 2:40 AM, Steven D'Aprano
wrote:
> Devin Jeanpierre wrote:
>
>> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
>>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote:
Another alternative is to put a list literal on the lefthand side:
>>
Devin Jeanpierre wrote:
> On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
>> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote:
>>> Another alternative is to put a list literal on the lefthand side:
>>>
>> def f(): yield 42
>>>
>>> ...
>> [result] = f()
>> res
On Wed, Feb 4, 2015 at 1:18 PM, Chris Angelico wrote:
> On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote:
>> Another alternative is to put a list literal on the lefthand side:
>>
> def f(): yield 42
>>
>> ...
> [result] = f()
> result
>> 42
>
> Huh, was not aware of
"ast" a écrit dans le message de
news:54d227ef$0$3292$426a7...@news.free.fr...
thanks for the answers
--
https://mail.python.org/mailman/listinfo/python-list
On Thu, Feb 5, 2015 at 4:36 AM, Peter Otten <__pete...@web.de> wrote:
> Another alternative is to put a list literal on the lefthand side:
>
def f(): yield 42
>
> ...
[result] = f()
result
> 42
Huh, was not aware of that alternate syntax.
> (If you're worried: neither the list nor
Rustom Mody wrote:
> Well its cryptic and confusing (to me at least)
> And is helped by adding 2 characters:
>
> (result,) = f()
>
> instead of
>
> result, = f()
Another alternative is to put a list literal on the lefthand side:
>>> def f(): yield 42
...
>>> [result] = f()
>>> result
42
(I
On 02/04/2015 07:04 AM, Chris Angelico wrote:
> On Thu, Feb 5, 2015 at 1:38 AM, Albert-Jan Roskam wrote:
>> I have also never seen this before, but perhaps this:
>>
> f = lambda: [42]
> result, = f()
> result
>> 42
>>
>> ... is slightly cleaner than this:
> result = f()[0]
> re
On Wednesday, February 4, 2015 at 8:14:29 PM UTC+5:30, Albert-Jan Roskam wrote:
> - Original Message -
>
> > From: Chris Angelico
> > Sent: Wednesday, February 4, 2015 3:24 PM
> > Subject: Re: meaning of: line, =
> >
> > On Thu, Feb 5, 2015 at 1:08 AM
On Thu, Feb 5, 2015 at 1:38 AM, Albert-Jan Roskam wrote:
> I have also never seen this before, but perhaps this:
>
f = lambda: [42]
result, = f()
result
> 42
>
> ... is slightly cleaner than this:
result = f()[0]
result
> 42
They're not technically identical. If the thing
- Original Message -
> From: Chris Angelico
> To:
> Cc: "python-list@python.org"
> Sent: Wednesday, February 4, 2015 3:24 PM
> Subject: Re: meaning of: line, =
>
> On Thu, Feb 5, 2015 at 1:08 AM, ast wrote:
>> I dont understand why there is a c
On Thu, Feb 5, 2015 at 1:08 AM, ast wrote:
> I dont understand why there is a comma just after line in the following
> command:
>
> line, = plt.plot(x, np.sin(x), '--', linewidth=2)
>
>
> I never saw that before
>
> Found here:
> http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash
You'll find some explanation here:
http://stackoverflow.com/questions/1708292/meaning-of-using-commas-and-underscores-with-python-assignment-operator
On Wed, Feb 4, 2015 at 12:08 PM, ast wrote:
> hello
>
> I dont understand why there is a comma just after line in the following
> command:
>
> line
hello
I dont understand why there is a comma just after line in the following
command:
line, = plt.plot(x, np.sin(x), '--', linewidth=2)
I never saw that before
Found here:
http://matplotlib.org/examples/lines_bars_and_markers/line_demo_dash_control.html
thanks
--
https://mail.python.org/m
25 matches
Mail list logo