通过Map()的Python列表联接产生“无类型”列表

时间:2019-06-27 07:38:38

标签: python arrays list

Python tips: Map, Filter Reduce的启发,我发表了以下声明:

globalTags = ['deviceName'\
    , 'processIndex'\
    , 'timingGroupID'\
    , 'sequenceIndex'\
    , 'chainIndex'\
    , 'eventNumber'\
    , 'chainStartStamp'\
    , 'acqStatus'\
    , 'sequenceStartStamp']

chargeTags = ['charge_status', 'charge_units']
chargeTags = list(map(lambda tag: chargeTags.append(tag), globalTags))

这将产生<class 'list'>: [None, None, None, None, None, None, None, None, None]而不是包含两个初始列表的值的预期联接列表。我做错了什么,什么会是更好的陈述?

1 个答案:

答案 0 :(得分:2)

您可以使用+运算符来连接数组。

globalTags = [
    'deviceName',
    'processIndex',
    'timingGroupID',
    'sequenceIndex',
    'chainIndex',
    'eventNumber',
    'chainStartStamp',
    'acqStatus',
    'sequenceStartStamp'
]

chargeTags = ['charge_status', 'charge_units']
chargeTags = chargeTags + globalTags