Thomas 'PointedEars' Lahn wrote:
> The original script already does not do what it advertises. Instead, it
> iterates over the characters of the string, attempts to convert each to an
> integer and then computes the sum. That is _not_ “calculate the total of
> numbers given in a string”.
Yes, a
Mark Lawrence wrote:
> On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:
>> I thought I had more than a fair grasp of regular expressions, but I am
>> puzzled by
>>
>> | $ python3
>> | Python 3.4.2 (default, Dec 27 2014, 13:16:08)
>> | [GCC 4.9.2] on linux
>> | >>> from re import findall
>> |
On 2015-01-12 00:04, Mark Lawrence wrote:
On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:
Store Makhzan wrote:
I have this script which can calculate the total of numbers given in a
string […]
total = 0
for c in '0123456789':
total += int(c)
print total
[…]
How should I modify this
Thomas 'PointedEars' Lahn wrote:
> This is safer:
>
> | >>> from re import split
> | >>> split(r'\s*,\s*', '1.23, 2.4, 3.123')
> | ['1.23', '2.4', '3.123']
Safer, slower, and unnecessary.
There is no need for the nuclear-powered bulldozer of regular expressions
just to crack this tiny peanut. W
Peter Otten wrote:
> Thomas 'PointedEars' Lahn wrote:
>> […] But float() is always necessary for computing the sum and suffices
>> indeed together with s.split() if s is just a comma-separated list of
>> numeric strings with optional whitespace leading and trailing the comma:
>>
>> print(sum
On Mon, Jan 12, 2015 at 11:09 AM, Peter Otten <__pete...@web.de> wrote:
>>
>> print(sum(map(lambda x: float(x), s.split(',')))
>>
>> Please trim your quotes to the relevant minimum.
>
> Hm, can you explain what this
>
> lambda x: float(x)
>
> is supposed to achieve? I mean other than to confuse a
Thomas 'PointedEars' Lahn wrote:
> Joel Goldstick wrote:
>
>> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
>> wrote:
>>> Joel Goldstick wrote:
Am I missing something.
>>>^
>>> […]
>>> You are missing a leading space character because in the string the
>
On 11/01/2015 23:07, Thomas 'PointedEars' Lahn wrote:
Store Makhzan wrote:
I have this script which can calculate the total of numbers given in a
string […]
total = 0
for c in '0123456789':
total += int(c)
print total
[…]
How should I modify this script to find the total of if the numbers
Joel Goldstick wrote:
> On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
> wrote:
>> Joel Goldstick wrote:
>>> Am I missing something.
>>^
>> […]
>> You are missing a leading space character because in the string the comma
>> was followed by one.
>
> I see that
On Sun, Jan 11, 2015 at 6:12 PM, Thomas 'PointedEars' Lahn
wrote:
> Joel Goldstick wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> Joel Goldstick wrote:
my_list = "1.23, 2.4, 3.123".split(",")
that will give you ['1.23', '2.4', '3.123']
>>>
>>> No, it gives
>>>
>>> […]
>>> | >>> my
Joel Goldstick wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Joel Goldstick wrote:
>>> my_list = "1.23, 2.4, 3.123".split(",")
>>>
>>> that will give you ['1.23', '2.4', '3.123']
>>
>> No, it gives
>>
>> […]
>> | >>> my_list = "1.23, 2.4, 3.123".split(",")
>> | >>> my_list
>> | ['1.23', ' 2.4', ' 3
On 2015-01-11, Joel Goldstick wrote:
> That's fine, but its different than your original question. In your
> original question you had a string of floats separated by commas. To
> solve that problem you need to first split the string on the commas:
>
> my_list = "1.23, 2.4, 3.123".split(",")
>
Store Makhzan wrote:
> I have this script which can calculate the total of numbers given in a
> string […]
> total = 0
> for c in '0123456789':
>total += int(c)
> print total
>
> […]
> How should I modify this script to find the total of if the numbers given
> in the string form have decimal
On Sun, Jan 11, 2015 at 5:20 PM, Thomas 'PointedEars' Lahn
wrote:
> Joel Goldstick wrote:
>
>> my_list = "1.23, 2.4, 3.123".split(",")
>>
>> that will give you ['1.23', '2.4', '3.123']
>
> No, it gives
>
> | $ python
> | Python 2.7.9 (default, Dec 11 2014, 08:58:12)
> | [GCC 4.9.2] on linux2
> | T
Joel Goldstick wrote:
> my_list = "1.23, 2.4, 3.123".split(",")
>
> that will give you ['1.23', '2.4', '3.123']
No, it gives
| $ python
| Python 2.7.9 (default, Dec 11 2014, 08:58:12)
| [GCC 4.9.2] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> my_list
On Sun, Jan 11, 2015 at 3:26 PM, Store Makhzan wrote:
> On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote:
>> On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote:
>> > I have this script which can calculate the total of numbers given in a
>> > string
>> > script -
>>
On Sunday, January 11, 2015 at 2:06:54 PM UTC-6, Joel Goldstick wrote:
> On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote:
> > I have this script which can calculate the total of numbers given in a
> > string
> > script -
> > total = 0
> > for c in '0123456789':
> >total += int(c)
On Sun, Jan 11, 2015 at 2:31 PM, Store Makhzan wrote:
> I have this script which can calculate the total of numbers given in a string
> script -
> total = 0
> for c in '0123456789':
>total += int(c)
> print total
> script -
>
> How should I modify this script to find the tota
I have this script which can calculate the total of numbers given in a string
script -
total = 0
for c in '0123456789':
total += int(c)
print total
script -
How should I modify this script to find the total of if the numbers given in
the string form have decimal places? That
19 matches
Mail list logo