List with duplicated values and suffix

前端 未结 6 1470
抹茶落季
抹茶落季 2020-11-30 02:48

I have a list, a:

a = [\'a\',\'b\',\'c\']

and need to duplicate some values with the suffix _ind added this way (

6条回答
  •  广开言路
    2020-11-30 03:32

    Another alternative with splicing (Python2.x, 3.x):

    result = [None] * len(a) * 2
    result[::2], result[1::2] = a, map(lambda x: x + '_ind', a)
    
    result
    # ['a', 'a_ind', 'b', 'b_ind', 'c', 'c_ind']
    

提交回复
热议问题