0

for example, if the string is "Nikki",

then how can I split it into "N", "i", "k", "k", "i"

help pls

Nikxith
  • 3
  • 1
  • ```[i for i in 'Nikki']``` also works! Check out Python documents about [str](https://docs.python.org/ko/3/library/stdtypes.html#textseq). – jupiterbjy Aug 19 '20 at 13:20

1 Answers1

7

You can just construct a list using the string

>>> list('Nikki')
['N', 'i', 'k', 'k', 'i']

Although for what it's worth, a list of chr is functionally equivalent to just iterating directly through the str itself. In other words

for letter in 'Nikki':

will work, as will anything relying on a sequence type.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218