I got it! One of the testcases was wrong,
([[1], [1]],[1],[1, 1]),
should be
([[1], [1]],[1],[1, 1, 1]),
And the working solution.
def supersum(sequence, start=0):
result = start
start = type(start)()
for item in sequence:
try:
I read through all of the posts and thanks for helping. What was supposed to be
simple a (recursively) straightforward, turned out to be quite tricky.
I've set up a small testing bench and tried all of the proposed solutions
including my own but none pass. I'll post it below.
I've also discover
On 06/07/2013 21:10, Rotwang wrote:
[...]
It's not quite clear to me what the OP's intentions are in the general
case, but calling supersum(item, start) seems odd - for example, is the
following desirable?
>>> supersum([[1], [2], [3]], 4)
22
I would have thought that the "correct" answer woul
On 06/07/2013 19:43, Joshua Landau wrote:
On 6 July 2013 13:59, Russel Walker wrote:
Since I've already wasted a thread I might as well...
Does this serve as an acceptable solution?
def supersum(sequence, start=0):
result = type(start)()
for item in sequence:
try:
On 7/6/2013 8:37 AM, Russel Walker wrote:
I know this is simple but I've been starring at it for half an hour and trying
all sorts of things in the interpreter but I just can't see where it's wrong.
def supersum(sequence, start=0):
result = start
for item in sequence:
try:
On 6 July 2013 13:59, Russel Walker wrote:
> Since I've already wasted a thread I might as well...
>
> Does this serve as an acceptable solution?
>
> def supersum(sequence, start=0):
> result = type(start)()
> for item in sequence:
> try:
> result += supersum(item, star
On Sat, Jul 6, 2013 at 10:37 PM, Russel Walker wrote:
> This works:
> - - - - - -
x = [[1], [2], [3]]
supersum(x)
> 6
supersum(x, [])
> [1, 2, 3]
>
>
> This does not:
> - - - - - - -
x = [[[1], [2]], [3]]
supersum(x, [])
> [1, 2, 1, 2, 3]
You have a problem of s
Russel Walker wrote:
> Since I've already wasted a thread I might as well...
>
> Does this serve as an acceptable solution?
>
> def supersum(sequence, start=0):
> result = type(start)()
> for item in sequence:
> try:
> result += supersum(item, start)
> except:
Since I've already wasted a thread I might as well...
Does this serve as an acceptable solution?
def supersum(sequence, start=0):
result = type(start)()
for item in sequence:
try:
result += supersum(item, start)
except:
result += item
return res
Nevermind!
Stupid of me to forget that lists or mutable so result and start both point to
the same list.
--
http://mail.python.org/mailman/listinfo/python-list
I know this is simple but I've been starring at it for half an hour and trying
all sorts of things in the interpreter but I just can't see where it's wrong.
def supersum(sequence, start=0):
result = start
for item in sequence:
try:
result += supersum(item, start)
On Saturday, 6 October 2012 02:09:56 UTC+5:30, Dave Angel wrote:
> On 10/05/2012 04:09 PM, Mike wrote:
>
> > Terry,
>
> >
>
> > I am not using the mail client. I am just posting on the site.
>
>
>
> And which site would that be (that you're using)? There are a few. I'm
>
> guessing you us
That worked, Ian.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
On 10/05/2012 04:09 PM, Mike wrote:
> Terry,
>
> I am not using the mail client. I am just posting on the site.
And which site would that be (that you're using)? There are a few. I'm
guessing you use google-groups. And all of them get gatewayed to the
actual list, with differing numbers of bugs
On Fri, Oct 5, 2012 at 2:03 PM, Mike wrote:
> I added the print command.
>
> It prints [] when there is no data.
Change "iter(next_r, None)" to "iter(next_r, [])"
--
http://mail.python.org/mailman/listinfo/python-list
Terry,
I am not using the mail client. I am just posting on the site.
Something wrong with this site. When you do individual reply, it does the
double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted
twice too.
Thanks
--
http://mail.python.org/mailman/listinfo/pytho
I added the print command.
It prints [] when there is no data.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Oct 5, 2012 at 7:39 AM, Mike wrote:
> Sorry about that. Here you go
>
> Traceback (most recent call last):
> File "test.py", line 17, in
> total = sum(float(col.value) for r in iter(next_r, None) for col in
> r[0].columns.itervalues())
> File "test.py", line 17, in
> total =
On 10/5/2012 9:47 AM, Mike wrote:
On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
Hi All,
I am new to python and am get
On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
> On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
>
> > On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
>
> >
>
> > > Hi All,
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > >
>
> >
>
> > > I am new
On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike wrote:
> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
>
> > Hi All,
>
> >
>
> >
>
> >
>
> > I am new to python and am getting the data from hbase.
>
> >
>
> > I am trying to do sum on the column as below
>
> >
>
> >
>
On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
> Hi All,
>
>
>
> I am new to python and am getting the data from hbase.
>
> I am trying to do sum on the column as below
>
>
>
>
>
> scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
>
> total = 0.0
>
> r =
On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike wrote:
> I agree with you, Ian. Thanks for all the help. Now I get the below error.
>
>
>
> File "test.py", line 17, in
>
> total = sum(float(col.value) for r in iter(next_r, None) for col in
> r[0].columns.itervalues())
>
> File "t
I agree with you, Ian. Thanks for all the help. Now I get the below error.
File "test.py", line 17, in
total = sum(float(col.value) for r in iter(next_r, None) for col in
r[0].columns.itervalues())
File "test.py", line 17, in
total = sum(float(col.value) for r in iter(next_r, None
On Thu, Oct 4, 2012 at 6:40 PM, Mike wrote:
> Traceback (most recent call last):
> File "test.py", line 16, in
> total = sum(float(col.value) for r in iter(next_r, None) for col in
> r.itervalues())
> File "test.py", line 16, in
> total = sum(float(col.value) for r in iter(next_r, N
On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote:
> On 10/04/2012 05:29 PM, Mike wrote:
>
> > I get below error
>
> >
>
> > NameError: name 'functools' is not defined
>
> >
>
>
>
> functools is a module in the standard library. You need to import it.
>
>
>
> import functool
On Fri, Oct 5, 2012 at 7:29 AM, Mike wrote:
> I get below error
>
> NameError: name 'functools' is not defined
>
> Thanks
functools is a module:
import functools
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
On 10/04/2012 05:29 PM, Mike wrote:
> I get below error
>
> NameError: name 'functools' is not defined
>
functools is a module in the standard library. You need to import it.
import functools
--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list
Thanks Ian for the quick reply.
I get the below error.
NameError: name 'itertools' is not defined
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
I get below error
NameError: name 'functools' is not defined
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly wrote:
> scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
> next_r = itertools.partial(client.scannerGet, scanner)
> total = sum(float(col.value) for r in iter(next_r, None) for col in
> r.itervalues())
That should be "functools" abo
On Thu, Oct 4, 2012 at 2:52 PM, wrote:
> scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
> total = 0.0
> r = client.scannerGet(scanner)
> while r:
> for k in (r[0].columns):
> total += float(r[0].columns[k].value)
> r = client.scannerGet(scanner)
>
> print total
>
>
Hi All,
I am new to python and am getting the data from hbase.
I am trying to do sum on the column as below
scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
total = 0.0
r = client.scannerGet(scanner)
while r:
for k in (r[0].columns):
total += float(r[0].columns[k].va
33 matches
Mail list logo