-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b76a5c
commit 6afb7d2
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# How to Join a String in Python | ||
|
||
This folder contains code associated with the Real Python tutorial on [How to Join a String in Python](https://realpython.com/python-join-string/). | ||
|
||
## About the Author | ||
|
||
Martin Breuss - Email: martin@realpython.com | ||
|
||
## License | ||
|
||
Distributed under the MIT license. See `LICENSE` for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"2025-01-24 10:00": ["click", "add_to_cart", "purchase"], | ||
"2025-01-24 10:05": ["click", "page_view"], | ||
"2025-01-24 10:10": ["page_view", "click", "add_to_cart"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import json | ||
|
||
|
||
def load_log_file(file_path): | ||
with open(file_path, mode="r", encoding="utf-8") as event_log_file: | ||
return json.load(event_log_file) | ||
|
||
|
||
def format_event_log(event_log): | ||
lines = [] | ||
for timestamp, events in event_log.items(): | ||
# Convert the events list to a string separated by commas. | ||
event_list_str = ", ".join(events) | ||
# Create a single line string. | ||
line = f"{timestamp} => {event_list_str}" | ||
lines.append(line) | ||
|
||
# Join all lines with a newline separator. | ||
return "\n".join(lines) | ||
|
||
|
||
if __name__ == "__main__": | ||
log_file_path = "event_log.json" | ||
event_log = load_log_file(log_file_path) | ||
output = format_event_log(event_log) | ||
print(output) |