'Print out json response list [duplicate]
This is a json response i received.
"allergens":[5 items
0:"msg_free"
1:"no_artificial_colors"
2:"no_artificial_flavors"
3:"no_artificial_ingredients"
4:"gluten_free"
]
I want to get each description in allergens however when i try the following code i get something like this.
allergies = response.json().get('allergens')
Outcome
['msg_free', 'no_artificial_colors', 'no_artificial_flavors', 'no_artificial_ingredients', 'gluten_free']
I would like to know how would i be able to print this out without it being in a list format without the brackets
Solution 1:[1]
your_list = ['msg_free', 'no_artificial_colors', 'no_artificial_flavors', 'no_artificial_ingredients', 'gluten_free']
to_be_filled = ", " # Comma separated is one option
to_be_filled.join(your_list) # The Argument could be any iterable
print(to_be_filled)
print(type(to_be_filled))
OUTPUT:
'msg_free, no_artificial_colors, no_artificial_flavors, no_artificial_ingredients, gluten_free'
<class 'str'>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JimShapedCoding |
