Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #198061
| From | ram@zedat.fu-berlin.de (Stefan Ram) |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: ''.join([bin(i)[2:].zfill(8) for i in flag]) |
| Date | 2026-09-23 23:09 +0000 |
| Organization | Stefan Ram |
| Message-ID | <bin-20260924000855@ram.dialup.fu-berlin.de> (permalink) |
| References | <nnd$45c195ac$47172e6f@35c50d4e9a8c02a9> |
Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
>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, isn't there a regular print-to-string-format function, something
>akin to C's sprintf(), that does this in a more succinct way?
Like,
''.join( f'{i:08b}' for i in flag )
?
>Here, `flag` is a string variable, if it's not clear from the con-
>text.
If "flag" would be a string, then "i" would be a string too,
but "bin" expects an integer.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
''.join([bin(i)[2:].zfill(8) for i in flag]) Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-24 06:42 +0800
Re: ''.join([bin(i)[2:].zfill(8) for i in flag]) ram@zedat.fu-berlin.de (Stefan Ram) - 2026-09-23 23:09 +0000
Re: format_binary Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-24 02:01 +0000
Re: format_binary Jon Ribbens <jon+usenet@unequivocal.eu> - 2026-09-24 06:57 +0000
Re: ''.join([bin(i)[2:].zfill(8) for i in flag]) Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-25 23:25 +0800
csiph-web