New to Python here and just looking for a little help. I have a list of dictionaries from a json file as follows:
x = [{'competition_id': 16, 'season_id': 4, 'country_name': 'Europe', 'competition_name': 'Champions League', 'competition_gender': 'male', 'season_name': '2018/2019'},
{'competition_id': 16, 'season_id': 1, 'country_name': 'Europe', 'competition_name': 'Champions League', 'competition_gender': 'male', 'season_name': '2017/2018'},
{'competition_id': 43, 'season_id': 3, 'country_name': 'International', 'competition_name': 'FIFA World Cup', 'competition_gender': 'male', 'season_name': '2018'}
]
Is there a way that I could filter this to just show me the "competition_name"
and corresponding "season_name"
?
I've tried the following:
newList = [i["competition_name"]for i in x],[i["season_name"]for i in x]
Which provides the following output as a tuple:
(['Champions League', 'Champions League', 'FIFA World Cup'], ['2018/2019', '2017/2018', '2018'])
But for a long list it's still hard to read, is there a way to print the output so the key/value pairs for each item are next to each other, eg
(['Champions League', '2018/2019'],['Champions League','2017/2018'], ['FIFA World Cup','2018'])
Hope that makes sense, thanks