Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Lists
- Write a function that remove duplicates from a list:
- for example:
- ```
- [1, 3, 5, 3, 7, 3, 1, 1, 5]
- ```
- should return
- ```
- [1, 3, 5, 7]
- ```
- Write a function that count each elements in a list:
- for example:
- ```
- [1, 3, 5, 3, 7, 3, 1, 1, 5]
- ```
- should become
- ```
- {
- 1: 3,
- 3: 3,
- 5: 2,
- 7: 1
- }
- ```
- # Run-Length Encoding
- Run-Length Encoding is a simple compression scheme. You replace consecutive
- occurence of the same later by the number of time it appears followed by the
- letter. You can suppose the string will only have letter from A to Z.
- Example:
- ```
- WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
- ```
- is compressed to:
- ```
- 12W1B12W3B24W1B14W
- ```
- # Run-Length Decoding
- Write the function to decode results from previous exercise:
- ```
- 12W1B12W3B24W1B14W
- ```
- should give:
- ```
- WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW
- ```
- # FizzBuzz
- Write a `fizzbuzz` function that takes no parameter
- as input and print in the console the numbers from 1
- to 100 and replace the number by:
- - Fizz if it is divisible by 3
- - Buzz if it is divisible by 5
- - FizzBuzz if it is divisible by both
- The beginning of the output should be:
- ```
- 1
- 2
- Fizz
- 4
- Buzz
- Fizz
- 7
- 8
- Fizz
- Buzz
- 11
- Fizz
- 13
- 14
- FizzBuzz
- 16
- ```
- # Dictionnary changes
- Write a function `replace_dashes` that takes a
- dictionnary as input and rename the keys so that
- every '_' is replaced by '-'.
- Your function should not change the values, for
- example, if the input is:
- ```
- {
- "key_1": "value_1",
- "key_2": "value_2",
- "key_3": {
- "key_4": "value_4"
- }
- }
- ```
- its output should be:
- ```
- {
- "key-1": "value_1",
- "key-2": "value_2",
- "key-3": {
- "key-4": "value_4"
- }
- }
- ```
- You can suppose that the input will be a valid JSON
- object.
- # Counting
- Write a program that outputs all possibilities to put + or - or nothing between
- the numbers 1,2,…,9 (in this order) such that the result is 100.
- For example
- ```
- 1 + 2 + 3 - 4 + 5 + 6 + 78 + 9 = 100
- ```
Add Comment
Please, Sign In to add comment