相当简单的问题。
如何从该返回数据中提取
spotify:artist:
值?
[{'external_urls':{'spotify':'https://open.spotify.com/artist/4RB42AM4VqzdHRQiVbzDU1'},'href':'https://api.spotify.com/v1/artists/4RB42AM4VqzdHRQiVbzDU1' , 'id': '4RB42AM4VqzdHRQiVbzDU1', '名称': 'Ismailovic', '类型': '艺术家', 'uri': 'spotify:艺术家:4RB42AM4VqzdHRQiVbzDU1'}, {'external_urls': {'spotify': 'https ://open.spotify.com/artist/6n18eBRlVxd4v4YnbbYlvs'},'href':'https://api.spotify.com/v1/artists/6n18eBRlVxd4v4YnbbYlvs','id':'6n18eBRlVxd4v4YnbbYlvs','名称':' Nabil Sansi', 'type': '艺术家', 'uri': 'spotify:artist:6n18eBRlVxd4v4YnbbYlvs'}, {'external_urls': {'spotify': 'https://open.spotify.com/artist/4Bv3GYUzNM11yYGQslJOkp' }, 'href': 'https://api.spotify.com/v1/artists/4Bv3GYUzNM11yYGQslJOkp', 'id': '4Bv3GYUzNM11yYGQslJOkp', '姓名': '先生。 ID', '类型': '艺术家', 'uri': 'spotify:艺术家:4Bv3GYUzNM11yYGQslJOkp'}]
artists_id
是数据,我尝试过:
print(artists_id[spotify:artist])
我期待
[4RB42AM4VqzdHRQiVbzDU1] [6n18eBRlVxd4v4YnbbYlvs] [4Bv3GYUzNM11yYGQslJOkp]
。
从数据中提取 Spotify:artist: 值:
spotify_artist_ids = [artist['id'] for artist in data]
print(spotify_artist_ids)
输出:
['4RB42AM4VqzdHRQiVbzDU1', '6n18eBRlVxd4v4YnbbYlvs', '4Bv3GYUzNM11yYGQslJOkp']
如果您想将每个 ID 括在方括号中并用空格分隔来格式化输出,则可以使用字符串格式化或列表理解来实现