Advertisement
furas

Python - sorting visualize - (Stackoverflow)

Apr 26th, 2024 (edited)
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # date: 2024.04.26
  2. # [python - missing spaces before string - Stack Overflow](https://stackoverflow.com/questions/78389448/missing-spaces-before-string)
  3.  
  4. def visualize(data: list):
  5.     what_to_print = ''
  6.  
  7.     maximum = max(data)
  8.  
  9.     for high in range(maximum, 0, -1):
  10.         what_to_print += f'{high:2}: '
  11.  
  12.         for item in data:
  13.             if item >= high:
  14.                 what_to_print += '|'
  15.             else:
  16.                 what_to_print += ' '
  17.         what_to_print += '\n'
  18.  
  19.     print(what_to_print, end='')
  20.    
  21. visualize([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  22. print('-----')
  23. visualize([5, 4, 3, 2, 1])
  24. print('-----')
  25. visualize([3, 5, 4, 0, 1, 2])
  26. print('-----')
  27.  
  28. """
  29. RESULT:
  30.  
  31. 10:          |
  32. 9:         ||
  33. 8:        |||
  34. 7:       ||||
  35. 6:      |||||
  36. 5:     ||||||
  37. 4:    |||||||
  38. 3:   ||||||||
  39. 2:  |||||||||
  40. 1: ||||||||||
  41. -----
  42. 5: |    
  43. 4: ||  
  44. 3: |||  
  45. 2: ||||
  46. 1: |||||
  47. -----
  48. 5:  |    
  49. 4:  ||  
  50. 3: |||  
  51. 2: |||  |
  52. 1: ||| ||
  53. -----
  54.  
  55. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement