Advertisement
Guest User

UUS TIMO!??

a guest
Oct 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. """Create schedule string from the given input string."""
  2. schedule_dict = create_schedule_dictionary(input_string)
  3. header = "time | items"
  4. content = ""
  5. if not schedule_dict:
  6. header_margin = 7
  7. empty_dict_string = "| No items found |"
  8. table_width = len(empty_dict_string)
  9. items_margin = 6
  10. content += empty_dict_string + " " * (table_width - len(empty_dict_string)) + "\n"
  11. else:
  12. longest_time = len(max(schedule_dict.keys(), key=len)) + 2
  13. longest_action = len(max(schedule_dict.values(), key=len)) + 2
  14. table_width = longest_action + longest_time + 3
  15. header_margin = longest_time + 7
  16. items_margin = longest_action - len("items") - 1
  17. for key in schedule_dict.keys():
  18. content += "|" + (longest_time - len(key) - 1) * " " + f"{key} | {schedule_dict[key]}" \
  19. + (longest_action - len(schedule_dict[key]) - 2) * " " + " |\n"
  20. schedule = table_width * "-" + f"\n|{header:>{header_margin}}" + items_margin * " " + "|\n" + table_width * "-" + "\n"
  21. schedule += content
  22. schedule += table_width * "-"
  23. return schedule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement