Deutsch English Français Italiano |
<solution-20240328180624@ram.dialup.fu-berlin.de> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Re: A missing iterator on itertools module? Date: 28 Mar 2024 17:07:25 GMT Organization: Stefan Ram Lines: 20 Expires: 1 Feb 2025 11:59:58 GMT Message-ID: <solution-20240328180624@ram.dialup.fu-berlin.de> References: <66059eb6$0$7522$426a34cc@news.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de d9Kl0N24pA+uEw/BL7MMHgUp8MibHsPA2VgZ0x9vVSyiCJ Cancel-Lock: sha1:tzVirbaOKjnUsswJxBS/MOxoGxg= sha256:G2hXAHd8hzPFzc9FD5yF1lNXyTuTnCMrHZueR5wF304= X-Copyright: (C) Copyright 2024 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-US Accept-Language: de-DE-1901, en-US, it, fr-FR Bytes: 2154 ast <none@none.fr> wrote or quoted: >s1 = "AZERTY" >s2 = "QSDFGH" >s3 = "WXCVBN" >and I need an itertor who delivers >A Q W Z S C E D C ... >I didn't found anything in itertools to do the job. >So I came up with this solution: >list(chain.from_iterable(zip("AZERTY", "QSDFGH", "WXCVBN"))) Maybe you meant "zip(s1,s2,s3)" as the definition of s1, s2, and s3 otherwise would not be required. Also the "list" is not necessary because "chain.from_iterable" already is an iterable. You could also use "*" instead of "list" to print it. So, import itertools as _itertools s =[ "AZERTY", "QSDFGH", "WXCVBN" ] print( *_itertools.chain.from_iterable( zip( *s ))) . But these are only minor nitpicks; you have found a nice solution!