Ask Your Question
0

Unsure why the 0 values error keeps coming up

asked 2013-06-03 14:06:38 +0100

JoshIzzard gravatar image

updated 2013-06-03 16:15:20 +0100

I am trying to code an algorithm to find the degrees of all small rank representations of $A_n$ that are equal to $p^2$ for some prime $p$. However, I think that my code should be correct, but it keeps giving me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_24.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("W2ZuYW1lLCBjbmFtZV0gPSBBX2NvbWIycmVwKDMp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>

  File "/tmp/tmp2u4eia/___code___.py", line 3, in <module>
    exec compile(u'[fname, cname] = A_comb2rep(_sage_const_3 )
  File "", line 1, in <module>

ValueError: need more than 0 values to unpack

The code for which it gives me this error is the following:

def A_comb2rep(p):
bound = p*p
name_fund = []
name_comb = []
A = lambda i: WeylCharacterRing("A{0}".format(i))
for i in range(bound):
    for k in range(1,bound+1):
        fw = A(i+1).fundamental_weights()
        if A(i+1)(k * fw[1]).degree > bound:
            break
        else:
            for v in fw:
                if A(i+1)(k * v).degree() == bound:
                    name_fund.append([])
                    name_fund[len(name_fund)-1].append('A'+str(i+1)+'('str(k)+str(v)+')')
for i in range(bound): # now onto combinations of two of the fws   #####
    for k in fw:
        fw = A(i+1).fundamental_weights()
        if A(i+1)(fw[1] + fw[2]).degree() > bound:
            break
        else:
            for j in fw:
                rep = A(i+1)(j+k)
                deg = rep.degree()
                if deg == bound:
                    name_comb.append([])
                    name_comb[len(name_comb)-1].append('A'+str(i+1)+'['+str(j)+'+'+str(k)+']')
return name_comb, name_fund

A helpful answer would be one that answers: What does ValueError: need more than 0 values to unpack mean and where should I look for tips on how to fix it.

Many thanks for your time.

edit retag flag offensive close merge delete

Comments

I do not understand your code. First of all the syntax '('str(k) is not valid (miss a +) and on the other hand "return" appear twice.

vdelecroix gravatar imagevdelecroix ( 2013-06-03 15:07:14 +0100 )edit

@vdelecroix I'm sorry, I was missing a `+` and I put the `return` statement that appears halfway down in order to see if the first output of my function was valid but I suppose this is not a correct debugging technique. I have edited the code to fix those two mistakes

JoshIzzard gravatar imageJoshIzzard ( 2013-06-03 16:18:10 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-06-03 16:19:16 +0100

tmonteil gravatar image

updated 2013-06-03 16:25:43 +0100

The problem comes from how you called your function. The function returns an empty list, but you try to assign two variables (fname and cname) with that output.

A simpler example:

sage: def my_empty_func():
sage:     return []
sage: a,b = my_empty_func()
...
ValueError: need more than 0 values to unpack

Here, the error means that you need the function my_empty_func() to return a list (or tuple) of two elements to feed a and b, but it returned a list of zero elements.

edit flag offensive delete link more

Comments

I see, I just corrected the range that the function needs to access and it worked perfectly. Thanks!

JoshIzzard gravatar imageJoshIzzard ( 2013-06-03 16:26:23 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-03 14:06:38 +0100

Seen: 755 times

Last updated: Jun 03 '13