fork(1) download
  1. # Swift's closure
  2. # https://d...content-available-to-author-only...e.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
  3.  
  4.  
  5. digitNames = {
  6. 0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four",
  7. 5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine"
  8. }
  9. numbers = [16, 58, 510]
  10.  
  11.  
  12. def convert_number_to_string(number):
  13. output = ''
  14. while number > 0:
  15. output = digitNames[number % 10] + output
  16. number /= 10
  17.  
  18. return output
  19.  
  20.  
  21. strings = map(convert_number_to_string, numbers)
  22.  
  23.  
  24. for s in strings:
  25. print(s)
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
OneSix
FiveEight
FiveOneZero