Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added computer_networks/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions computer_networks/char_stuffing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FLAG = "~"
ESC = "#"


def char_stuffing(s: str) -> str:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: s

"""
Return the char stuffed message
>>> char_stuffing("abc")
"abc"
>>> char_stuffing("a#b#c")
"a##b##c"
"""
arr = list()

Check failure on line 13 in computer_networks/char_stuffing.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (C408)

computer_networks/char_stuffing.py:13:11: C408 Unnecessary `list` call (rewrite as a literal)
for i in s:
arr.append(i)
for i in range(len(arr)):
if arr[i] == FLAG and not (i == 0 or i == len(arr) - 1):
arr[i] = ESC + arr[i]
elif arr[i] == ESC:
arr[i] += ESC
return "".join(arr)


s = "~abc#~cde~ab~"
print(char_stuffing(s))
Loading