0

Simply put, why do this work:

class A:
    x = {'a': 'b', 'c': 'd'}
    y = ", ".join([f"{key}: {val}" for key, val in x.items()])

yet this doesn't:

class A:
    x = {'a': 'b', 'c': 'd'}
    y = ", ".join([f"{key}: {x[key]}" for key in x])

Both work outside the class definition, so I'm not sure what's the interaction with the f-strings.

Tonechas
  • 12,665
  • 15
  • 42
  • 74
nestor556
  • 390
  • 2
  • 14

0 Answers0