Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My new branch #11651

Closed
wants to merge 13 commits into from
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