Rodrick Brown writes:
> BANANA FRIES 12
> POTATO CHIPS 30
> APPLE JUICE 10
> CANDY 5
> APPLE JUICE 10
> CANDY 5
> CANDY 5
> CANDY 5
> POTATO CHIPS 30
>
> I'm expecting the following output
> BANANA FRIES 12
> POTATO CHIPS 60
> APPLE JUICE 20
> CANDY 20
>>> data =["BANANA FRIES 12",
..."P
On 14 March 2016 at 23:59, Steven D'Aprano wrote:
> On Tue, 15 Mar 2016 02:06 am, Oscar Benjamin wrote:
>
>> On 14 March 2016 at 14:35, Rick Johnson
>> wrote:
>>>
>>> I would strongly warn anyone against using the zip function
>>> unless
>> ...
>>> I meant to say: absolutely, one hundred percent
Steven D'Aprano writes:
> On Tuesday 15 March 2016 16:26, Jussi Piitulainen wrote:
>
>> Steven D'Aprano writes:
>>
>>> Unfortunate or not, it seems to be quite common that "zip"
>>> (convolution) discards items when sequences are of different lengths.
>>
>> Citation needed. Where is zip called c
On Tue, Mar 15, 2016 at 7:39 PM, Steven D'Aprano
wrote:
>> Why should zip be called convolution?
>
> Why should anything be called anything?
>
> Don't worry, I'm not suggesting that the zip function be renamed.
>
It's like referring to the 'and' and 'or' operators as conjunctions
and disjunctions
On Tuesday 15 March 2016 16:26, Jussi Piitulainen wrote:
> Steven D'Aprano writes:
>
>> Unfortunate or not, it seems to be quite common that "zip"
>> (convolution) discards items when sequences are of different lengths.
>
> Citation needed. Where is zip called convolution?
Wikipedia :-)
Unfort
Steven D'Aprano writes:
> Unfortunate or not, it seems to be quite common that "zip"
> (convolution) discards items when sequences are of different lengths.
Citation needed. Where is zip called convolution?
Why should zip be called convolution?
> See https://en.wikipedia.org/wiki/Convolution_%2
On Tue, 15 Mar 2016 02:06 am, Oscar Benjamin wrote:
> On 14 March 2016 at 14:35, Rick Johnson
> wrote:
>>
>> I would strongly warn anyone against using the zip function
>> unless
> ...
>> I meant to say: absolutely, one hundred percent *SURE*, that
>> both sequences are of the same length, or, ab
On Monday, March 14, 2016 at 10:17:54 AM UTC-5, Ian wrote:
> It's sometimes very useful [for zip to discard values],
> though.
The obvious solution is to allow the caller to decide if the
error should be raised, or not. Currently, the caller has no
control over the internals of zip unless he crea
On Monday, March 14, 2016 at 10:06:56 AM UTC-5, Oscar Benjamin wrote:
> On 14 March 2016 at 14:35, Rick Johnson wrote:
> >
> > I would strongly warn anyone against using the zip function
> > unless
> ...
> > I meant to say: absolutely, one hundred percent *SURE*, that
> > both sequences are of the
Ian Kelly wrote:
> On Mon, Mar 14, 2016 at 9:06 AM, Oscar Benjamin
> wrote:
>> On 14 March 2016 at 14:35, Rick Johnson
>> wrote:
>>>
>>> I would strongly warn anyone against using the zip function
>>> unless
>> ...
>>> I meant to say: absolutely, one hundred percent *SURE*, that
>>> both sequenc
On 2016-03-14 15:22, Rick Johnson wrote:
On Monday, March 14, 2016 at 9:19:04 AM UTC-5, alister wrote:
A code smell does not necessarily mean the code is wrong,
just that it warrants investigation as there is a strong
possibility it may be sub- optimal
Yes, technically speaking, you're correct
On Monday, March 14, 2016 at 9:19:04 AM UTC-5, alister wrote:
> A code smell does not necessarily mean the code is wrong,
> just that it warrants investigation as there is a strong
> possibility it may be sub- optimal
Yes, technically speaking, you're correct.
But the concept of "code smell" has
On 14/03/2016 15:06, Oscar Benjamin wrote:
On 14 March 2016 at 14:35, Rick Johnson wrote:
I would strongly warn anyone against using the zip function
unless
...
I meant to say: absolutely, one hundred percent *SURE*, that
both sequences are of the same length, or, absolutely one
hundred perc
On Mon, Mar 14, 2016 at 9:06 AM, Oscar Benjamin
wrote:
> On 14 March 2016 at 14:35, Rick Johnson wrote:
>>
>> I would strongly warn anyone against using the zip function
>> unless
> ...
>> I meant to say: absolutely, one hundred percent *SURE*, that
>> both sequences are of the same length, or, a
On 14 March 2016 at 14:35, Rick Johnson wrote:
>
> I would strongly warn anyone against using the zip function
> unless
...
> I meant to say: absolutely, one hundred percent *SURE*, that
> both sequences are of the same length, or, absolutely one
> hundred percent *SURE*, that dropping values is n
On Thursday, March 10, 2016 at 8:04:04 PM UTC-6, Mark Lawrence wrote:
> On 11/03/2016 01:45, BartC wrote:
> > [...]
> > Any other way of traversing two lists in parallel?
> >
>
> Use zip()
Sure, the zip function is quite handy, but it can produce
subtle bugs when both sequences are not of the same
On Mon, 14 Mar 2016 07:07:45 -0700, Rick Johnson wrote:
> On Thursday, March 10, 2016 at 7:22:26 PM UTC-6, Mark Lawrence wrote:
>> Always a code smell when range() and len() are combined.
>
> I would be careful about dealing in absolutes Mark.
a code smell does not necesarily mean the code is wr
On Mon, Mar 14, 2016 at 10:07 AM, Rick Johnson
wrote:
> On Thursday, March 10, 2016 at 7:22:26 PM UTC-6, Mark Lawrence wrote:
>> Always a code smell when range() and len() are combined.
>
> I would be careful about dealing in absolutes Mark.
I always think people should never use absolutes.
--
h
On Thursday, March 10, 2016 at 7:22:26 PM UTC-6, Mark Lawrence wrote:
> Always a code smell when range() and len() are combined.
I would be careful about dealing in absolutes Mark.
--
https://mail.python.org/mailman/listinfo/python-list
On 11/03/2016 02:03, Mark Lawrence wrote:
On 11/03/2016 01:45, BartC wrote:
On 11/03/2016 01:21, Mark Lawrence wrote:
On 11/03/2016 00:05, BartC wrote:
def last(a):
return a[-1]
def init(a): # all except last element
return a[0:len(a)-1]
What is wrong with a[0:1]
On Thu, Mar 10, 2016 at 4:05 PM, BartC wrote:
> Here's a rather un-Pythonic and clunky version. But it gives the expected
> results. (I've dispensed with file input, but that can easily be added
> back.)
>
> def last(a):
> return a[-1]
>
> def init(a): # all except last elemen
On 11/03/2016 01:56, Martin A. Brown wrote:
for i in range(len(names)):
print (names[i],totals[i])
Always a code smell when range() and len() are combined.
Any other way of traversing two lists in parallel?
Yes. Builtin function called 'zip'.
https://docs.python.org/3/library/fu
On 11/03/2016 01:45, BartC wrote:
On 11/03/2016 01:21, Mark Lawrence wrote:
On 11/03/2016 00:05, BartC wrote:
def last(a):
return a[-1]
def init(a): # all except last element
return a[0:len(a)-1]
What is wrong with a[0:1] ?
The returns the head of the list. I ne
>>> for i in range(len(names)):
>>> print (names[i],totals[i])
>>
>> Always a code smell when range() and len() are combined.
>
> Any other way of traversing two lists in parallel?
Yes. Builtin function called 'zip'.
https://docs.python.org/3/library/functions.html#zip
Toy example:
im
On Thu, Mar 10, 2016 at 8:45 PM, BartC wrote:
> Any other way of traversing two lists in parallel?
zip
--
https://mail.python.org/mailman/listinfo/python-list
On 11/03/2016 01:21, Mark Lawrence wrote:
On 11/03/2016 00:05, BartC wrote:
def last(a):
return a[-1]
def init(a): # all except last element
return a[0:len(a)-1]
What is wrong with a[0:1] ?
The returns the head of the list. I need everything except the last
elem
On 11/03/2016 00:05, BartC wrote:
On 10/03/2016 09:02, Rodrick Brown wrote:
From the following input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30
I'm expecting the following output
BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 2
On 10/03/2016 09:02, Rodrick Brown wrote:
From the following input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30
I'm expecting the following output
BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20
Here's a rather un-Py
On Fri, Mar 11, 2016 at 10:24 AM, Gregory Ewing
wrote:
> Instead, pull them out and give them meaningful names.
> Doing so with the above code gives:
>
> name = m.group(1)
> value = m.group(2)
> if name not in od.keys():
> od[name] = int(value)
> else:
> od[name] += int(od.get(name
Rodrick Brown wrote:
if m.group(1) not in od.keys():
od[m.group(1)] = int(m.group(2))
else:
od[m.group(1)] += int(od.get(m.group(1),0))
Others have pointed out what's wrong with this, but here's
a general tip: Don't repeat complicated subexpressions
such as m.group(1
On 3/10/2016 4:02 AM, Rodrick Brown wrote:
From the following input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30
I'm expecting the following output
BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20
However my code seems
Thomas 'PointedEars' Lahn wrote:
> od = OrderedDict()
This is pointless, then.
> […]
> od = OrderedDict(map(lambda item: (item[0], 0), items))
> for item in items: od[item[0]] += item[1]
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail
Thomas 'PointedEars' Lahn wrote:
[
> key = m.group(1)
> value = int(m.group(2))
>
> if key not in od:
> od[key] = value
> else:
> od[key] += value
>
> But there is probably an even more pythonic way to do this.
]
For example, based on the orig
Thomas 'PointedEars' Lahn wrote:
> key = m.group(1)
> value = int(m.group(1))
value = int(m.group(2))
> if key not in od:
> od[key] = value
> else:
> od[key] += value
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bit
Rodrick Brown wrote:
> […]
> if m:
> if m.group(1) not in od.keys():
> od[m.group(1)] = int(m.group(2))
> else:
> od[m.group(1)] += int(od.get(m.group(1),0))
> […]
This program logic appears to be wrong as you are not adding the value that
you just read to the dic
Rodrick Brown wrote:
> From the following input
>
> 9
> BANANA FRIES 12
> POTATO CHIPS 30
> APPLE JUICE 10
> CANDY 5
> APPLE JUICE 10
> CANDY 5
> CANDY 5
> CANDY 5
> POTATO CHIPS 30
>
> I'm expecting the following output
> BANANA FRIES 12
> POTATO CHIPS 60
> APPLE JUICE 20
> CANDY 20
>
> Howeve
Hi.
This looks a little like a homework problem, so I'll be cryptic ... :)
On 10/03/16 09:02, Rodrick Brown wrote:
From the following input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30
if m:
if m.group(1) not
>From the following input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30
I'm expecting the following output
BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20
However my code seems be returning incorrect value
#!/usr/bin/env
38 matches
Mail list logo