-5

I want to join the foll:

col = ('NS', 2013L)

to get:

'NS_2013'

I am doing this:

'_'.join(str(col)), and I get this: "(_'_N_S_'_,_ _2_0_1_3_L_)"
user308827
  • 21,227
  • 87
  • 254
  • 417

3 Answers3

2
>>> col = ('NS', 2013L)
>>> col
('NS', 2013L)
>>> '%s_%d' % col
'NS_2013'
Kohei Sugimura
  • 326
  • 1
  • 10
1

You need to use string formatting.

>>> col = ('NS', 2013L)
>>> '{}_{}'.format(col[0], col[1])
'NS_2013'
Chad S.
  • 6,252
  • 15
  • 25
1

The mistake you are making is in applying the str invocation to the entire col tuple rather than the elements of col:

col = ('NS', 2013L)
'_'.join(str(element) for element in col)

yields:

'NS_2013"

which I believe is what you are after.

chucksmash
  • 5,777
  • 1
  • 32
  • 41