-2

Looking over some class notes and I came across this piece of code. I copied it exactly from the notes but when i run it, it gives me a syntax error on the final line. Anyone able to point out the mistake?

    phone_book = { 'joe' : '086 7346659',
       'jimmy' : '085 2313872',
       'cindy' : '087 9452238' }

    print(sorted(phone_book.items()))
    for k, v in sorted(phone_book.items()):
       print(f' {k} ---> {v}')

1 Answers1

1

I don't know if this will help. Your code seems to work fine on python3.7 through python3.9.

Though it doesn't work on 2.7. Try this instead.

phone_book = { 'joe' : '086 7346659',
       'jimmy' : '085 2313872',
       'cindy' : '087 9452238' }

print(sorted(phone_book.items()))
for k, v in sorted(phone_book.items()):
    print(k+' ---> '+v)
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44
  • Answer is better than comments. If you think the comments have valuable info, you can edit that into your answer, so the comments could be deleted. – anatolyg Apr 03 '21 at 17:45