Guest User

Untitled

a guest
Apr 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. arr = ['hello' ',' , 'how', 'is' , 'your', 'day', 'going', '?' , '#', 'HelloWorld']
  2.  
  3. N = 0
  4. for index to arr:
  5. if arr[N] == '#':
  6. arr[N] = (' ')
  7. arr[N+1] = (' ')
  8. N += 1
  9.  
  10. arr = ['a', 'b', '#', 'aa']
  11. indices = [idx for idx, elt in enumerate(arr) if elt == '#']
  12.  
  13. for idx in indices:
  14. if idx != len(arr): arr[idx+1] = ' ' # Check if not at the end of the list
  15. arr[idx] = ' '
  16.  
  17. for i in range(len(arr)):
  18. if arr[i] == '#':
  19. arr[i] = ' '
  20. if i < len(arr)-2:
  21. arr[i+1] = ' '
  22.  
  23. arr = ['hello' ',' , 'how', 'is' , 'your', 'day', 'going', '?' , '#', 'HelloWorld']
  24.  
  25. for index in range(0, len(arr)):
  26. if arr[index] == '#':
  27. arr[index:index+2] = ['', '']
  28. print (arr)
  29.  
  30. ['hello,', 'how', 'is', 'your', 'day', 'going', '?', '', '']
  31. [Finished in 0.133s]
  32.  
  33. arr = ['hello' ',' , 'how', 'is' , 'your', 'day', 'going', '?' , '#', 'HelloWorld', '#']
  34.  
  35. for index in range(0, len(arr)):
  36. if arr[index] == '#':
  37. arr[index:index+2] = ['', '']
  38. print (arr)
  39.  
  40. ['hello,', 'how', 'is', 'your', 'day', 'going', '?', '', '', '', '']
  41. [Finished in 0.179s]
Add Comment
Please, Sign In to add comment