I wanna convert this to a regular for loop
for i in sorted(pdict.items(),key=lambda x:x[1],reverse=True):
if(i[1]<rating):
print("Jersey number: " str(i[0]) ", Rating: " str(i[1]))
CodePudding user response:
you mean like this?
for i in pdict.items():
if(i[1]<rating):
print("Jersey number: " str(i[0]) ", Rating: " str(i[1]))
CodePudding user response:
convert this to a regular for loop
Ok, here you go.
for i in pdict.items():
if i[1] < rating:
print("Jersey number: " str(i[0]) ", Rating: " str(i[1]))
But perhaps you wanted to clarify your question?
CodePudding user response:
You can also make i
more explicitly defined by specifying that two values are coming from .items()
: the dictionary key and the dictionary value. The syntax below makes that more clear.
for key, value in pdict.items():
if value < rating:
print(f"Jersey number: {key}, Rating: {value}")