Ask Your Question
0

TypeError: 'sage.rings.integer.Integer' object is not iterable

asked 7 years ago

anonymous user

Anonymous

This is my code

m=[1,2,3,4]
c=[[1,3],[2,3],[1,2],[3,4]]

for i in Subsets(m):
    print(i)
    alpha_ij=0
    for j in c:
        delta_ij=set(i).symmetric_difference(set(j))
        print(delta_ij)

        for i in delta_ij:
            alpha_ij=alpha_ij+2^i
    print(alpha_ij)

When I compile it I get

{}
set([1, 3])
Traceback (most recent call last):        for j in c:
  File "", line 1, in <module>

  File "/tmp/tmpgaYE70/___code___.py", line 10, in <module>
    delta_ij=set(i).symmetric_difference(set(j))
TypeError: 'sage.rings.integer.Integer' object is not iterable

Which I do not understand because I do not think that I have iterated over any integer in any part of the code. The problem seem to be the last three lines because if delete them and compile the code there does not appear any error.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
5

answered 7 years ago

Change the variable in your third loop from i to, say, k. The variable i is supposed to be a subset of m.

Preview: (hide)
link

Comments

Thank you, it works. Somehow I thought that I can treat the variable i in the third loop more or less like a bound variable in the predicate logic.

kristi gravatar imagekristi ( 7 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 7 years ago

Seen: 3,764 times

Last updated: Mar 21 '18