• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Python dict() to Jython in eclipse

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know a simple solution to converting python dict() to jython in eclipse?
I just want to index two pre-existing lists. List of names, list of values), names[0] = values[0] that sort of thing.

Thanks
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following works in Jython - do I understand the question correctly ?

>>> dict({1:2})
{1: 2}
 
Ranch Hand
Posts: 343
Mac OS X Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still confused, what exactly is the problem?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

lee fair wrote:I just want to index two pre-existing lists. List of names, list of values), names[0] = values[0] that sort of thing.

Thanks



That seems like zip() not dict():



The output is:
('1', 'one')
('2', 'two')
('3', '3')

So zip makes a List of tuples, indexing each list passed in equally. If you wanted to turn that into a dictionary you do:


which gives me:
{'1': 'one', '3': '3', '2': 'two'}

I am working Python, not Jython, so what of that is what you want, and what is not working?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic