0

I keep getting a syntax error for this and Google is no help for my specific issue.

I'm trying to merge two data sets into a single dictionary. One data set comes from https://universalis.app/api/v2/marketable and looks to be an array. The other comes from https://raw.githubusercontent.com/ffxiv-teamcraft/ffxiv-teamcraft/master/apps/client/src/assets/data/items.json and appears to be just an object of objects. Example below with what I've tried.

Code:

import requests
import json

url = "https://universalis.app/api/v2/marketable"
response = json.loads(requests.get(url).text)
marketableItems = [
    item
    for item in response
]

url = "https://raw.githubusercontent.com/ffxiv-teamcraft/ffxiv-teamcraft/master/apps/client/src/assets/data/items.json"
allItemsResponse = json.loads(requests.get(url).text)
itemDictionary = [
    Item, allItemsResponse[str(Item)]["en"]
    for Item in marketableItems
]

this produces:

    Item, allItemsResponse[str(Item)]["en"]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: did you forget parentheses around the comprehension target?

I've googled a fair bit for this exact Syntax Error, but I'm not really able to find any sort of guide on how to join two objects like this. I'm able to get allItemsResponse[str(Item)]["en"] to return data, I just want it paired with the original data from the first URL.

Joel Trauger
  • 720
  • 1
  • 4
  • 24
  • You need to do exactly what it says, put parentheses around the target (and turn it into a tuple), or alternatively if you're trying to make a dict, use a dictionary comprehension: `{ Item : allItemsResponse[str(Item)]["en"] for Item in marketableItems }` – Nick Jun 28 '22 at 06:17
  • RIGHT ON, that solved it. I was missing the tuple bit. I'll play around with tuple vs dictionary style and see which works best with how I'm trying to use the data. Thanks! Can you add your comment as an answer so I can mark it solved? – Joel Trauger Jun 28 '22 at 06:28
  • I'm pretty sure this is a dupe. Take the answer and run :) – Nick Jun 28 '22 at 06:31

0 Answers0