Is this what you are trying to do:
In [199]: list1 = ['abc','foo','bar']
In [200]: list2 = list('1234')
In [201]: [[a+b for b in list2] for a in list1]
Out[201]:
[['abc1', 'abc2', 'abc3', 'abc4'],
['foo1', 'foo2', 'foo3', 'foo4'],
['bar1', 'bar2', 'bar3', 'bar4']]
The equivalent using np.char.add
and broadcasting:
In [210]: np.char.add(np.array(list1)[:,None], np.array(list2))
Out[210]:
array([['abc1', 'abc2', 'abc3', 'abc4'],
['foo1', 'foo2', 'foo3', 'foo4'],
['bar1', 'bar2', 'bar3', 'bar4']], dtype='<U4')
For this small example the list comprehension version is faster.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…