0

I have two lists of names that are the same length and I'd simply like to combine them into a third list so the first value in each list is combined, then the second, and so forth. I know I'm missing something very obvious.

I've tried using "+" but that doesn't work for the two lists.

mgr_name = pd_ex.iloc[3,:].tolist()

prod_name = pd_ex.iloc[4,:].tolist()

I would like the output to be: [mgr_name 1 + " " + prod_name 1, mgr_name 2 + " " + prod_name 2, ...]

AAA
  • 3,520
  • 1
  • 15
  • 31
Dan
  • 11
  • 4

2 Answers2

3

This will yield the list you seek:

[x[0]+' '+x[1] for x in zip(prod_name,mgr_name)]
Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
1

Try this:

mgr_name = pd_ex.iloc[3,:].tolist()
prod_name = pd_ex.iloc[4,:].tolist()
third_name = [mgr_name[i] + ' ' + prod_name[i] for i in range(0, len(mgr_name))]
AAA
  • 3,520
  • 1
  • 15
  • 31
Cao Minh Vu
  • 1,900
  • 1
  • 16
  • 21