0

I have scoured the internet and I cannot find any reference to this type of for loop:

variable = [(item["attribute1"], item["attribute2]") for item in piece_of_json_data]

I am using this to update wtform's SelecField choices:

form.SelectField.choices = variable

but I can only get it to work if I replace one of the attributes in parenthesis with a static number:

variable = [(1, item["attribute2"]) for item in piece_of_json_data]

but that sets the value of the option field to "1", when I need the option values to be one of the attributes as a string.

Does this create a dict? a tuple? is there some kind of terminology for this that I can use to find documentation?

bigbounty
  • 14,834
  • 4
  • 27
  • 58
JSum
  • 557
  • 7
  • 19

1 Answers1

0

Thanks to the comments, I now understand that I am using list comprehension to create a tuple. The tuple works fine with both string and integer values. My issue has to do with .choices not accepting a string.

I found that my only problem is that I had coerce set to int on my selectfield, so naturally it wanted an integer.

JSum
  • 557
  • 7
  • 19