From Newsgroup: comp.lang.python
Dear comp.lang.python,
As the topic says, is
''.join([bin(i)[2:].zfill(8) for i in flag])
really the most Pythonic way to do this? I mean, why are we converting
each character in the flag [1] to a binary string, chunk off the first
two bytes, and then fill up the front with zeros [2], just to join it
with an empty string?
I mean, isn't there a regular print-to-string-format function, something
akin to C's sprintf(), that does this in a more succinct way? Can we do something like
flag.expand_to_binary() ## ?
Here, it should be obvious that `flag` is indeed of the A.S.C.I.I. sub-
set, but this doesn't seem like it would work well, if the text is Uni-
code and U.T.F.-8.
This is a single line from the Cryptohack competition, but I am assuming
the authors of the website are cryptographers, and not expert Pythonics.
What do you think?
[1] Here, `flag` is a string variable, if it's not clear from the con-
text.
[2] Or is it the back, as I haven't used zfill() before?
--
Johann | email: invalid -> com |
http://www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | via XS News
https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
--- Synchronet 3.22a-Linux NewsLink 1.2