python标识符中的字符无效_Python标识中的无效字符

下面的python代码在标识符中得到错误的无效字符。知道为什么吗?这是一个我正在编写的未完成的函数,由于这个错误它没有运行,所以没有返回。在def spotifyrecs(mylibrary, newsongs):

total = 0

count = 0

genredict = {}

for artist in mylibrary:

artistsongs = mylibrary[artist]

for adict in artistsongs:

total += adict["plays"]

count += 1

if adict["genre"] not in genredict:

genredict[adict["genre"]] = 1

if adict["genre"] in genredict:

genredict[adict["genre"]] += 1

avgplays = round(total / count, 2)

genrelist = []

for genre in genredict:

newtup = (genredict[genre], genre)

genrelist.append(newtup)

genrelist.sort(reverse = True)

return None

library = ​{"Ariana Grande": [{"title": "thank u, next", "plays": 100, "genre": "pop"}, {"title": "Last Christmas", "plays": 44, "genre": "Christmas"}], "Khalid":[{"title": "Location", "plays": 15, "genre": "R&B"}, {"title": "Young, Dumb, and Broke", "plays": 90, "genre": "R&B"}]}

songs = [{"title": "Loving is Easy", "artist": "Rex Orange County", "plays": 115, "genre": "R&B"}, {"title": "Halo", "artist": "Beyonce", "plays": 9, "genre": "R&B"}, {"title": "Focus", "artist": "Ariana Grande", "plays": 112, "genre": "pop"}, {"title": "Winter", "artist": "Khalid", "plays": 800, "genre": "R&B"}]

print(spotifyrecs(library, songs))

错误:

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值