why cannot recalculate?

asked 13 years ago

canisvetus gravatar image

updated 13 years ago

Shashank gravatar image

These code work fine

html("<h1> From Dictionary to Matrix (1)</h1>")
    @interact
    def newtarph( D=input_box(default={0:{1:3}, 1: {0: 2, 4: 2, 5: 2}, 2: {0: 3, 1: 4}}, label='Dictionary')):
        E=[]
        for u in D.keys():
            for i in range(len(D.values()[u])):        
              E.append([u, D.values()[u].keys()[i], D.values()[u].values()[i]])
        print matrix(E)

These other code d'ont work:

html("<h1> From Dictionary to Matrix (1)</h1>")
    @interact
    def newtarph( D=input_box(default={1: {0: 2, 4: 2, 5: 2}, 2: {0: 3, 1: 4}}, label='Dictionary')):
        E=[]
        for u in D.keys():
            for i in range(len(D.values()[u])):        
              E.append([u, D.values()[u].keys()[i], D.values()[u].values()[i]])
        print matrix(E)
Preview: (hide)

Comments

What is your question exactly? Seems to work for me

Shashank gravatar imageShashank ( 13 years ago )

Yes, seems to work, but if you modifie the dictionary, you can obtein an error

canisvetus gravatar imagecanisvetus ( 13 years ago )

Modifying the dictionary seems to work fine for me. Can you tell us exactly how to modify it and exactly what the error is (just copy and paste the error message.)

Jason Grout gravatar imageJason Grout ( 13 years ago )

Excuse me Shashank and Jason Grout. Perhaps I make a mistake writen the dictionary. Now work also for me. Eusebio Corbacho.

canisvetus gravatar imagecanisvetus ( 13 years ago )

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_20.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("X2ludGVyYWN0Xy51cGRh\ dGUoJzQwJywgJ0QnLCA0LCBfaW50ZXJhY3RfLnN0YW5kYXJkX2I2NGRlY29kZSgnZXpFNklI\ c3dPaUF6TENBeU9pQTBmU3dnTWpvZ2V6TTZJRElzSURRNklERjlMQ0F6T2lCN01Eb2dNaXdn\ TVRvZ015d2dORG9nTVgxOScpLCBnbG9iYWxzKCkpOyBfaW50ZXJhY3RfLnJlY29tcHV0ZSgn\ NDAnKTs="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/tmp/tmpx7r7GI/___code___.py", line 3, in <module> exec compile(u"_interact_.update('40', 'D', _sage_const_4 , _interact_.standard_b64decode('ezE6IHswOiAzLC

canisvetus gravatar imagecanisvetus ( 13 years ago )