How To Remove Quotes From String in Python -


currently have list of strings, lets say:

list1 = [1,2,3,4] 

i want convert list of numbers corresponding letters, using:

output = [chr(ord((str(x+96)))) x in list1] 

when this, error saying program expects string length of one, in code gives string length of 3 because of '' around each number after converted string. conversion string necessary because has in string format in order ord work.

so question guys how can fix and/or rid of these quotes?

in case wondering, supposed come out as

output = [a,b,c,d] 

printing list prints string representation of elements includes single quotes around string elements inside list. instead format string yourself:

>>> '[{}]'.format(','.join([chr((x+96)) x in list1])) '[a,b,c,d]' 

or in printed form:

>>> print '[{}]'.format(','.join([chr((x+96)) x in list1])) [a,b,c,d] 

the format method allows format string. in case, curly braces used placeholder value include in final string. square brackets part of format provide actual array-like output. join method takes array of objects , joins them form single combined string. in case, i've joined several objects using literal comma. produces comma separated string output. inner list comprehension code had provided.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -