0

Can any one tell me how to split a list, if its possible. Want to split it word by word.

my list contains links like:

 ['14th_century;15th_century;16th_century;Pacific_Ocean;Atlantic_Ocean;Accra;Africa;Atlantic_slave_trade;African_slave_trade']

Now, i want to use the split method, to split up 14th_century and 15th_century, so it is 2 words, and so on with all links.

So for every sign " ; " it should just split it.

right now i made a for loop.

for line in loops:

UPDATE:

have done it so far as this.

links = []    
for line in newPath:
    links.append(line[3:4])

old_list = []
new_list = []

old_list = links
new_list = old_list[0].split(';')

print new_list
Pixel
  • 349
  • 1
  • 8
  • 17

2 Answers2

1

You can simply do:

my_list = old_list[0].split(';')

Examples

>>> old_list = ['14th_century;15th_century;16th_century;Pacific_Ocean;Atlantic_Ocean;Accra;Africa;Atlantic_slave_trade;African_slave_trade']

>>> my_list = old_list[0].split(';')
['14th_century', '15th_century', '16th_century', 'Pacific_Ocean', 'Atlantic_Ocean', 'Accra', 'Africa', 'Atlantic_slave_trade', 'African_slave_trade']
sshashank124
  • 31,495
  • 9
  • 67
  • 76
0

You can simply do:

paths = ['abc;def;ghi', 'jkl;mno;pqr']
paths = [path.split(';') for path in paths]
>>> paths
[['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']]
Scorpion_God
  • 1,499
  • 10
  • 15