Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # date: 2024.04.26
- # [python - missing spaces before string - Stack Overflow](https://stackoverflow.com/questions/78389448/missing-spaces-before-string)
- def visualize(data: list):
- what_to_print = ''
- maximum = max(data)
- for high in range(maximum, 0, -1):
- what_to_print += f'{high:2}: '
- for item in data:
- if item >= high:
- what_to_print += '|'
- else:
- what_to_print += ' '
- what_to_print += '\n'
- print(what_to_print, end='')
- visualize([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
- print('-----')
- visualize([5, 4, 3, 2, 1])
- print('-----')
- visualize([3, 5, 4, 0, 1, 2])
- print('-----')
- """
- RESULT:
- 10: |
- 9: ||
- 8: |||
- 7: ||||
- 6: |||||
- 5: ||||||
- 4: |||||||
- 3: ||||||||
- 2: |||||||||
- 1: ||||||||||
- -----
- 5: |
- 4: ||
- 3: |||
- 2: ||||
- 1: |||||
- -----
- 5: |
- 4: ||
- 3: |||
- 2: ||| |
- 1: ||| ||
- -----
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement