how can i concat these values properly: test = [{"vendorProject": "SAP", "product":…
- User
how can i concat these values properly:
test = [{"vendorProject": "SAP", "product": "NetWeaver"}, {"vendorProject": "N/A", "product": "N/A"}]
for t in test: concatenated = t.get('vendorProject', "N/A") + t.get('product', "N/A") print(concatenated)
Assistant
The issue with your current code is that you're trying to concatenate the values directly without any separator, which can make the output hard to read (especially if either value is "N/A"). Here's how you can improve it:
test = [{"vendorProject": "SAP", "product": "NetWeaver"}, {"vendorProject": "N/A", "product": "N/A"}] for t in test: vendor = t.get('vendorProject', "N/A") product = t.get('product', "N/A") concatenated = f"{vendor} - {product}" # Using a separator print(concatenated)This will output:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.