I think better is:
d = {'A': ['blue', 'blue', 'blue', 'red', 'red', 'red', 'yellow',
'yellow', 'green', 'green', 'green'],
'B': ['a', 'a', 'b', 'c', 'c', 'c', 'd', 'e', 'f', 'f', 'g'],
'C': ['a1', 'a2', 'b1', 'c1', 'c2', 'c3', 'd1', 'e1', 'f1', 'f2', 'g1']}
df = pd.DataFrame(d)
print (df)
A B C
0 blue a a1
1 blue a a2
2 blue b b1
3 red c c1
4 red c c2
5 red c c3
6 yellow d d1
7 yellow e e1
8 green f f1
9 green f f2
10 green g g1
keylist = df.apply(lambda x: '/'.join(x), axis=1).add('/X').values.tolist()
print (keylist)
['blue/a/a1/X', 'blue/a/a2/X', 'blue/b/b1/X', 'red/c/c1/X', 'red/c/c2/X',
'red/c/c3/X', 'yellow/d/d1/X', 'yellow/e/e1/X',
'green/f/f1/X', 'green/f/f2/X', 'green/g/g1/X']
Or if only few columns:
keylist = (df['A'] + '/' + df['B'] + '/' + df['C'] + '/X').values.tolist()
Some timings:
#[110000 rows x 3 columns]
df = pd.concat([df] * 10000, ignore_index=True)
In [364]: %%timeit
...: (df['A'] + '/' + df['B'] + '/' + df['C'] + '/X').values.tolist()
...:
60.2 ms ± 1.04 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [365]: %%timeit
...: df.apply(lambda x: '/'.join(x), axis=1).add('/X').tolist()
...:
2.48 s ± 39.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [366]: %%timeit
...: list1, list2, list3 = df['A'].tolist(), df['B'].tolist(), df['C'].tolist()
...: for i in zip(list1, list2, list3):
...: val = map(str, i)
...: keylist.append('/'.join(val))
...: keylist[-1] += '/X'
...:
192 ms ± 78.5 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [367]: %%timeit
...: df.iloc[:,0].str.cat([df[c] for c in df.columns[1:]],sep='/').tolist()
...:
61.1 ms ± 540 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [368]: %%timeit
...: df.assign(New='X').apply('/'.join,1).tolist()
...:
2.51 s ± 76.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [369]: %%timeit
...: ['{0}/{1}/{2}/X'.format(i, j, k) for i, j, k in df.values.tolist()]
74.6 ms ± 2.27 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
val = map(str, i) keylist.append('/'.join(val+'X'))in your for loop!