repeat items in a list
Paul Rubin
no.email at nospam.invalid
Sun Mar 27 01:35:28 EDT 2016
More information about the Python-list mailing list
Sun Mar 27 01:35:28 EDT 2016
- Previous message (by thread): repeat items in a list
- Next message (by thread): repeat items in a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
beliavsky at aol.com writes: > yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx])) The chain approach seems more natural to me: yy = list(chain.from_iterable(map(lambda x: [x,x], xx))) may make the doubling more obvious, and in Python 3 it should avoid the intermediate lists since map creates a generator. Depending on the usage, you might also not need the outermost list, making yy a lazy generator as well.
- Previous message (by thread): repeat items in a list
- Next message (by thread): repeat items in a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list