-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_)"
0

3 Answers 3

2
>>> col = ('NS', 2013L)
>>> col
('NS', 2013L)
>>> '%s_%d' % col
'NS_2013'
Sign up to request clarification or add additional context in comments.

Comments

1

You need to use string formatting.

>>> col = ('NS', 2013L)
>>> '{}_{}'.format(col[0], col[1])
'NS_2013'

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.