Guest User

Untitled

a guest
Jan 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. # Lists
  2.  
  3. Write a function that remove duplicates from a list:
  4. for example:
  5. ```
  6. [1, 3, 5, 3, 7, 3, 1, 1, 5]
  7. ```
  8. should return
  9. ```
  10. [1, 3, 5, 7]
  11. ```
  12.  
  13. Write a function that count each elements in a list:
  14. for example:
  15. ```
  16. [1, 3, 5, 3, 7, 3, 1, 1, 5]
  17. ```
  18. should become
  19. ```
  20. {
  21. 1: 3,
  22. 3: 3,
  23. 5: 2,
  24. 7: 1
  25. }
  26. ```
  27.  
  28. # Run-Length Encoding
  29.  
  30. Run-Length Encoding is a simple compression scheme. You replace consecutive
  31. occurence of the same later by the number of time it appears followed by the
  32. letter. You can suppose the string will only have letter from A to Z.
  33.  
  34. Example:
  35. ```
  36. WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
  37. ```
  38. is compressed to:
  39. ```
  40. 12W1B12W3B24W1B14W
  41. ```
  42.  
  43. # Run-Length Decoding
  44.  
  45. Write the function to decode results from previous exercise:
  46. ```
  47. 12W1B12W3B24W1B14W
  48. ```
  49. should give:
  50. ```
  51. WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
  52. ```
  53.  
  54. # FizzBuzz
  55.  
  56. Write a `fizzbuzz` function that takes no parameter
  57. as input and print in the console the numbers from 1
  58. to 100 and replace the number by:
  59. - Fizz if it is divisible by 3
  60. - Buzz if it is divisible by 5
  61. - FizzBuzz if it is divisible by both
  62.  
  63. The beginning of the output should be:
  64. ```
  65. 1
  66. 2
  67. Fizz
  68. 4
  69. Buzz
  70. Fizz
  71. 7
  72. 8
  73. Fizz
  74. Buzz
  75. 11
  76. Fizz
  77. 13
  78. 14
  79. FizzBuzz
  80. 16
  81. ```
  82.  
  83.  
  84. # Dictionnary changes
  85.  
  86. Write a function `replace_dashes` that takes a
  87. dictionnary as input and rename the keys so that
  88. every '_' is replaced by '-'.
  89. Your function should not change the values, for
  90. example, if the input is:
  91. ```
  92. {
  93. "key_1": "value_1",
  94. "key_2": "value_2",
  95. "key_3": {
  96. "key_4": "value_4"
  97. }
  98. }
  99. ```
  100. its output should be:
  101. ```
  102. {
  103. "key-1": "value_1",
  104. "key-2": "value_2",
  105. "key-3": {
  106. "key-4": "value_4"
  107. }
  108. }
  109. ```
  110. You can suppose that the input will be a valid JSON
  111. object.
  112.  
  113.  
  114. # Counting
  115. Write a program that outputs all possibilities to put + or - or nothing between
  116. the numbers 1,2,…,9 (in this order) such that the result is 100.
  117. For example
  118. ```
  119. 1 + 2 + 3 - 4 + 5 + 6 + 78 + 9 = 100
  120. ```
Add Comment
Please, Sign In to add comment