Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Create schedule string from the given input string."""
- schedule_dict = create_schedule_dictionary(input_string)
- header = "time | items"
- content = ""
- if not schedule_dict:
- header_margin = 7
- empty_dict_string = "| No items found |"
- table_width = len(empty_dict_string)
- items_margin = 6
- content += empty_dict_string + " " * (table_width - len(empty_dict_string)) + "\n"
- else:
- longest_time = len(max(schedule_dict.keys(), key=len)) + 2
- longest_action = len(max(schedule_dict.values(), key=len)) + 2
- table_width = longest_action + longest_time + 3
- header_margin = longest_time + 7
- items_margin = longest_action - len("items") - 1
- for key in schedule_dict.keys():
- content += "|" + (longest_time - len(key) - 1) * " " + f"{key} | {schedule_dict[key]}" \
- + (longest_action - len(schedule_dict[key]) - 2) * " " + " |\n"
- schedule = table_width * "-" + f"\n|{header:>{header_margin}}" + items_margin * " " + "|\n" + table_width * "-" + "\n"
- schedule += content
- schedule += table_width * "-"
- return schedule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement