hi,

i'm having trouble taking say the input of the user and converting it to the right type of format i need in order to compare them.

An example is say I have the number 1234 and that is assigned to the variable x and the string value of that is assigned to y. How would i go from this string to one which looked like ?

I thought i would iterate over the string and append each value, however i was unsuccessful with this code.

a=[]
x=1234
y=str(x)
for i in y:
    a.append(str(y))

The reason i am doing this is so i can compare this to another value with a simliar format, as well as a side function to this i would like to convert this format back to just a string however for that part I am lost.

cheers for any help you can give me

Recommended Answers

All 4 Replies

x = 1234
y = str(x)
a = list(y)
print ', '.join(repr(var) for var in (x,y,a))

thanks, alot but is there no way to go from that format back to the original of just a single string?

x = 1234
y = str(x)
a = list(y)
astring = ''.join(a)
print ', '.join(repr(var) for var in (x,y,a,astring))

Correcting your original thought ...

a = []
x = 1234
y = str(x)
for character in y:
    a.append(character)

print(a)  # ['1', '2', '3', '4']
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.