1

I am trying to create a very simple program for averaging numbers. And one part of it involves converting an input string into an array.

E.g.

average = input()

average becomes 'Hello world! This is a string.'

I then need to split it into an array like this:

average = ['Hello', 'world!', 'This', 'is', 'a', 'string.']

What would be a way of going about this?

0

2 Answers 2

1

Simply use the split function :

lst = txt.split(" ")
Sign up to request clarification or add additional context in comments.

Comments

0
separator = " "
average = input()
print average.split(separator)

There is a inbuilt method called split() which will get your job done , you can pass a separator variable to that method indicating the character you want to split upon However the default value is space " " itself , averge.split() would also work fine in your case.

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.