Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dictionary support #6

Closed
fredglass opened this issue Feb 19, 2016 · 4 comments
Closed

dictionary support #6

fredglass opened this issue Feb 19, 2016 · 4 comments

Comments

@fredglass
Copy link

I was trying out the examples from the python tutorial at https://docs.python.org/3/tutorial/ , but almost none of the dictionary examples work. Below is the code I am using. Am I doing something wrong? Is more support planned in the future?

Almost all the other tutorial code I have tried has worked great so far. Very exciting project, thank you!

def test():

    #examples from
    #https://docs.python.org/3/tutorial/datastructures.html#dictionaries

    tel = {'jack': 4098, 'sape': 4139}
    tel['guido'] = 4127

    print (tel) #{'sape': 4139, 'guido': 4127, 'jack': 4098}
    print (tel['jack']) #4098

    del tel['sape']
    tel['irv'] = 4127
    print (tel) #{'guido': 4127, 'irv': 4127, 'jack': 4098}

    #ERROR Uncaught TypeError: tel.keys is not a function:
    print ( list(tel.keys()) ) #['irv', 'guido', 'jack']
    print ( sorted(tel.keys()) ) #['guido', 'irv', 'jack']

    #ERROR Uncaught TypeError: container.indexOf is not a function:
    print ('guido' in tel) #True
    print ('jack' not in tel) #False

    #ERROR Uncaught ReferenceError: pair is not defined:
    print ( dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])) #{'sape': 4139, 'jack': 4098, 'guido': 4127}

    knights = {'gallahad': 'the pure', 'robin': 'the brave'}

    #ERROR Uncaught TypeError: knights.items is not a function:
    for k, v in knights.items():
        print (k, v)
        #gallahad the pure, robin the brave

    if 'gallahad' in knights:
        print ('gallahad is a knight') #gallahad is a knight

    for k in knights:
        print (k) #gallahad, robin

test()
@JdeH
Copy link
Collaborator

JdeH commented Feb 19, 2016

I don't think you're doing anything wrong.
Seems that quite some things have fallen over or were omitted here.
I'll correct that and add this example to the autotest.

Thanks!

EDIT: Apart from the 'del' and 'for k in knights' it all works now (I had done some unfortunate edits and the autotest didn't catch them, now it does), but I haven't yet committed. Especially the 'for k in knights' requires some careful thought to prevent all 'for ... in ...' loops from becoming slow.

@techdragon
Copy link

@JdeH is there a previous version where this does work? or is the issue all in new code?

@JdeH
Copy link
Collaborator

JdeH commented Feb 22, 2016

There's no (uploaded) version in which this all works. The fact of the matter is that I started implementing the dicts some time ago but got distracted by another problem and forgot to finish them. However in the version I'm working on most of it is fixed. But I haven't yet tested well enough. Should be completed in 1 -2 weeks from now.

@JdeH
Copy link
Collaborator

JdeH commented Feb 28, 2016

Fixed and uploaded. Automatic conversion to keys () iterable, like in 'for k in knights' can be switched on and off with a command line switch or locally with pragma ('iconv') resp. pragma ('noiconv'). I'll close the issue, feel free to reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants