ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 14 Feb 2014 22:29:19 +0100ValueError: too many values to unpackhttps://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/I want try prime ideal factorzation in extension field,how to run [i.L.is_galois() for i, _ in SUB]
http://sagenb.skku.edu/home/pub/143/
Fri, 14 Feb 2014 07:02:24 +0100https://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/Answer by lftabera for <p>I want try prime ideal factorzation in extension field,how to run [i.L.is_galois() for i, _ in SUB]</p>
<p><a href="http://sagenb.skku.edu/home/pub/143/">http://sagenb.skku.edu/home/pub/143/</a></p>
https://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/?answer=16039#post-id-16039In order to unpack multiple values by multiple assignments in python 2.7 you need as many variables as values to unpack.
In your example, the elements of SUB are tuples of three elements, so you would have to do
for i, _ , _ in SUB
Yes, you can put the same variable multiple times, try to understand what python does with
a, b, b, a = range(4)
On the other hand, "i" will not have a method called "L", so you probably want
[i.is_galois() for i, _, _ in SUB]
Or, even better, avoid multiple assignment usign:
[i[0].is_galois() for i in SUB]
Fri, 14 Feb 2014 07:38:31 +0100https://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/?answer=16039#post-id-16039Comment by cjsh for <p>In order to unpack multiple values by multiple assignments in python 2.7 you need as many variables as values to unpack.</p>
<p>In your example, the elements of SUB are tuples of three elements, so you would have to do</p>
<p>for i, _ , _ in SUB</p>
<p>Yes, you can put the same variable multiple times, try to understand what python does with</p>
<p>a, b, b, a = range(4)</p>
<p>On the other hand, "i" will not have a method called "L", so you probably want</p>
<p>[i.is_galois() for i, _, _ in SUB]</p>
<p>Or, even better, avoid multiple assignment usign:</p>
<p>[i[0].is_galois() for i in SUB]</p>
https://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/?comment=16043#post-id-16043thank you very much!
you are master! Fri, 14 Feb 2014 22:29:19 +0100https://ask.sagemath.org/question/11034/valueerror-too-many-values-to-unpack/?comment=16043#post-id-16043