Ask Your Question
0

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

asked 2018-03-21 12:30:36 +0100

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2018-03-21 13:11:51 +0100

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

edit flag offensive delete link more

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 ( 2018-03-21 15:15: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

1 follower

Stats

Asked: 2018-03-21 12:30:36 +0100

Seen: 3,674 times

Last updated: Mar 21 '18