more_itertools.interleave(*iterables)[source]
Return a new iterable yielding from each iterable in turn, until the shortest is exhausted. >>> list(interleave([1, 2, 3], [4, 5], [6, 7, 8])) [1, 4, 6, 2, 5, 7] For a version that doesn’t terminate after the shortest iterable is exhausted, see interleave_longest(). If you want just the same item interleaved, use itertools.repeat(). This approach gets you VASTLY more than the suggestion, but includes it as a trivial case. On Tue, Jun 6, 2023 at 10:09 PM Matthias Görgens < matthias.goerg...@gmail.com> wrote: > This is sometimes a nice function to have. For example, Haskell has a > similar function: > https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-List.html#v:intercalate > that I use in real code every once in a while. > > But I don't think you need to stick this function in the standard library. > A third party library works just as well. > > The only thing missing is that you can't use the > `my_list.function_name(other_arguments)| syntax easily, and will call as > `function_name(my_list, other_arguments)`. But that seems a small price to > pay. > > On Wed, 7 Jun 2023, 08:00 Samuel Muldoon, <muldoonsam...@gmail.com> wrote: > >> To Whom it May Concern, >> >> Python's `str` class has a method named `join` >> >> I was wondering if a future release of python could have a `list.join` >> which behaves in a similar fashion. >> >> >> >> *result = [99].join([1, 2, 3])print(result)# prints [1, 99, 2, 99, 3]* >> >> >> *Samuel Muldoon* >> >> *(720) 653 -2408* >> >> *muldoonsam...@gmail.com <muldoonsam...@gmail.com>* >> >> >> >> _______________________________________________ >> Python-ideas mailing list -- python-ideas@python.org >> To unsubscribe send an email to python-ideas-le...@python.org >> https://mail.python.org/mailman3/lists/python-ideas.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-ideas@python.org/message/FWF5WSSUQLLCJNZZ3V3KZITNT5KBSWPE/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/W7PBHDCIGJM7DOS5SQHSC5RGBYWNVS3V/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- The dead increasingly dominate and strangle both the living and the not-yet born. Vampiric capital and undead corporate persons abuse the lives and control the thoughts of homo faber. Ideas, once born, become abortifacients against new conceptions.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/S777LUISXC34ZITD2LKCZ5FEKSATDS7S/ Code of Conduct: http://python.org/psf/codeofconduct/