fork(4) download
  1. # A set containing every value in range(5):
  2. five_set = {x for x in range(5)}
  3. print (five_set)
  4. # Out: {0, 1, 2, 3, 4}
  5.  
  6. # A set of even numbers between 1 and 10:
  7. even_set = {x for x in range(1, 11) if x % 2 == 0}
  8. print (even_set)
  9. # Out: {2, 4, 6, 8, 10}
  10.  
  11. # Unique alphabetic characters in a string of text:
  12. text = "When in the Course of human events it becomes necessary for one people..."
  13. new_set = {ch.lower() for ch in text if ch.isalpha()}
  14. print (new_set)
  15. # Out: {'i', 'e', 'b', 'c', 'r', 'p', 's', 'f', 'h', 'a', 'm', 'v', 'n', 't', 'u', 'w', 'o', 'y', 'l'}
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
{0, 1, 2, 3, 4}
{8, 2, 10, 4, 6}
{'f', 't', 'i', 'r', 'v', 'b', 'u', 'y', 'l', 'p', 's', 'w', 'h', 'e', 'c', 'm', 'a', 'n', 'o'}