Skip to content

Commit

Permalink
Make pgn_format() code easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkZH committed Feb 28, 2024
1 parent 8756e78 commit 603c975
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ def set(self, new_comment: Union[str, list[str]]) -> None:

def pgn_format(self) -> str:
"""Create a string representation of the comments in PGN format."""
comments = list(map(lambda s: s.replace("{", ""), self._comments))
comments = list(map(lambda s: s.replace("}", "").strip(), comments))
comments = list(filter(None, comments))
return "{ " + " } { ".join(comments) + " }"
comments = map(lambda s: s.replace("{", ""), self._comments)
comments = map(lambda s: s.replace("}", "").strip(), comments)
return " ".join(f"{{ {comment} }}" for comment in comments if comment)

def remove_empty(self) -> None:
"""Remove empty comments from the comment list."""
Expand Down

0 comments on commit 603c975

Please sign in to comment.