Advertisement
makispaiktis

Testing 1-2-3 - Codewars

Nov 24th, 2019 (edited)
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. '''
  2.  
  3. Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.
  4.  
  5. Write a function which takes a list of strings and returns each line prepended by the correct number.
  6.  
  7. The numbering starts at 1. The format is n: string. Notice the colon and space in between.
  8.  
  9. Examples:
  10.  
  11. number([]) # => []
  12. number(["a", "b", "c"]) # => ["1: a", "2: b", "3: c"]
  13.  
  14. '''
  15.  
  16. def number(lines):
  17.     resultList = []
  18.     for i in range(0, len(lines)):
  19.         element = str(i+1) + ": " + lines[i]
  20.         resultList.append(element)
  21.     return resultList
  22.  
  23. # MAIN FUNCTION
  24. print(number(["hello", "my", "friend"]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement