0

I'm having issues with raw_input again, this time trying to turn the value I get into a list. Here is my code:

original = raw_input("Type is your input? ")
original_as_array = list('original')
print original_as_array
for i in range(0,len(original)):
    print i

my print original_as_array literally prints ['o', 'r', 'i'.... etc]. If we pretend that my input is Hello World, I want original_as_array to output: ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o'... etc]. I think I'm making a tiny mistake. Can you point me in the right direction:)?

3 Answers 3

3

Quotes form a string literal.

original_as_array = list(original)
Sign up to request clarification or add additional context in comments.

Comments

1
original = raw_input("Type is your input? ")
original_as_array = list(original) # no quotes. If you put quotes, you are turning it into a string.
print original_as_array
for i in original_as_array: # this is shorter way to iterate and print than your method
    print i

Comments

1

Strings are already iterable, so you don't need to convert it to a list, so you can easily go :

original = raw_input("Type is your input? ")
# or if you really want a list
original_as_list = list(original) # NOT 'original', that's passing the string original not the value of original
for letter in original:
    print letter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.