Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Python dict() to Jython in eclipse

 
lee fair
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
karthik raghunathan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the following works in Jython - do I understand the question correctly ?

>>> dict({1:2})
{1: 2}
 
Palak Mathur
Ranch Hand
Posts: 328
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still confused, what exactly is the problem?
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic