0

I have a list

list = ['a:b:c:d', 'e:f:g:h', 'i:j:k:l']

What I'm trying to do is make a list of each of it's elements. Something like this:

listelement[0] = list[0].split(':')
print(listelement[0][1])

output: b

I can't seem to figure out how to create something that works similarly to this.

1 Answers1

3

You can try list comprehension to do what you want.

new_list = [element.split(':') for element in list].

Also I would advise against the use of list as a name, since it's a reserved word.

thethiny
  • 1,125
  • 1
  • 10
  • 26