Tom E. O'Neil
Tom E. O'Neil

Reputation: 557

How to convert a list of numbers to a list of strings?

I'm knocking my head against a wall regarding adding quotes to a list of numbers.

How do I add single quotes to this list of numbers?

num = [1, 2, 3, 4]

Upvotes: 2

Views: 135

Answers (4)

Sumana
Sumana

Reputation: 27

Try this solution:

    x = [1,2,3,4]
    x = map(lambda x: str(x), x)x = list(x)
    print(x)
    str(x)

Upvotes: 0

Gnaneshwar Babu
Gnaneshwar Babu

Reputation: 111

num= list(map(str, num))
print(num)
#output
['1', '2', '3', '4']

Upvotes: 2

Subhrajyoti Das
Subhrajyoti Das

Reputation: 2710

Try this:

num = [1, 2, 3, 4]
new_list = [str(i) for i in num]

#output
print(new_list)
['1', '2', '3', '4']

Upvotes: 4

oppressionslayer
oppressionslayer

Reputation: 7224

here you go: :-)

In [1335]: str(num)                                                                                                                                                                                        
Out[1335]: '[1, 2, 3, 4]'

Upvotes: 1

Related Questions