Idiomatic way of repeating items in a sequence.

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Jun 30 11:59:25 EDT 2003


>>>>> "alr" == alr  <anlri at wmdata.com> writes:

    alr> reduce(lambda l, i: l + i, [[item] * repetitions for item in
    alr> sequence])


Oops, premature hit of send key.  What I meant to say was

  seq = ['a', 'b', 'c']
  print [x for x in seq for i in range(len(seq))]

JDH






More information about the Python-list mailing list