0

I don't quite understand why their is a C in the beginning of the {}. Is this just syntax for comprehensive sets?

x= {c for c in "I've got plenty of nothing"} print(sorted(x))

This prints: [' ', "'", I, 'e', 'f', 'g', 'h', 'i', 'l', 'n', 'o', 'p', 't,' 'v', 'y'] Can someone explain why I need a c before the for loop?

Gabe
  • 9
  • notably it doesn't have to be a `c`. `{any_identifier for any_identifier in some_sequence}` is fine too. The `for x in y` part is naming the `x` that comes out of iterating over `y`. The first identifier is what we keep (so `{x**2 for x in y}` would keep the square of each number in `y`) – Adam Smith Apr 11 '17 at 23:41
  • 1
    You need a c because otherwise it's a syntax error? – OneCricketeer Apr 11 '17 at 23:51

0 Answers0