1

Is there any way to split a string such as '00:00' into an array such as ['0', '0, ':' , '0', '0'] ? I have tried:

time = raw_input()
digital = time.split()

where time is the input string '00:00'.

1 Answer 1

5

No need to split, you can simply use list(..):

digital = list(time)

A string is a iterable: you can iterate over the characters. The list(..) constructor takes as input an iterable, and constructs a list where each element of the iterable (the characters in this case), is an element of the list.

For example:

>>> time = raw_input()
00:00
>>> list(time)
['0', '0', ':', '0', '0']
Sign up to request clarification or add additional context in comments.

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.