Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : no viable alternative at input 'for' Python

I have strange problem,

when i am using Netbeans IDE , this line :

total_stock = {items : 0 for items in product_stock}

causes syntax Error:

Syntax Error : no viable alternative at input 'for'

But the same code runs perfectly fine in terminal and returns this

>> {'rom_price': 0, 'rim_price': 0, 'ram_price': 0}

I am using python 2.7+ at terminal and python plugin Version: 0.107 and Jython plugin Version: 2.12 Source: Python for netbeans 8.0

How to solve this problem??

like image 914
Himanshu97 Avatar asked Aug 08 '14 09:08

Himanshu97


1 Answers

Looks like jython is not able to do dictionary comprehension. As a workaround use the dictionary constructor in combination with a generator.

total_stock = dict((item, 0) for item in product_stock)
like image 101
miindlek Avatar answered Oct 04 '22 15:10

miindlek