Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail 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: 23 Sep 2026 23:09:14 GMT Organization: Stefan Ram Lines: 21 Expires: 1 Sep 2027 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de lleePlc5ODhnCIuyJIX0/wMa30lunSPmY8xBHCFxVZeaQj Cancel-Lock: sha1:+EEkQKOXyx0Ixw00vs/GPaMblsc= sha256:TQjf8OvOpdy3sDEiJAX8cDm9otOvUmSGuodyfUq5gi0= X-Copyright: (C) Copyright 2026 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en Xref: csiph.com comp.lang.python:198061 Johann 'Myrkraverk' Oskarsson 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.