0

I have an example list

['i,am,a,dog,i,am,a,king,king,is,god,god,made,humans,dog,loves,humans']

The problem is that all the words are on the same index. Please suggest how can we convert it into a proper list with all words at different indexes.

Apologies in advance as I don't know how to frame the title for this issue.

result:

['i','am','a','dog','i','am','a','king','king','is','god','god','made','humans','dog','loves','humans']
2
  • Try mylist[0].split(‘,’) Commented Apr 2, 2020 at 10:45
  • Additionally, this is very basic Python data structure manipulation. I recommend taking a Python tutorial as this will give you the foundation you will need. Commented Apr 2, 2020 at 10:51

3 Answers 3

2

Please try:

my_list = ['i,am,a,dog,i,am,a,king,king,is,god,god,made,humans,dog,loves,humans']
new_list = mylist[0].split(",")
Sign up to request clarification or add additional context in comments.

Comments

0

This should do:

splitted_list = single_index_list[0].split(",")

Comments

0

You can do:

L = ['i,am,a,dog,i,am,a,king,king,is,god,god,made,humans,dog,loves,humans']
L[0].split(',')

split(',') will split your single index string to multiple strings

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.