how to remove none from the for loop - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: how to remove none from the for loop (/thread-2221.html) |
how to remove none from the for loop - desul - Feb-27-2017 Dear all, c= " domain ontologies" mystr = c.split(' ') c= [i for i in mystr[:1]] print(c)result
RE: how to remove none from the for loop - wavic - Feb-27-2017 [i for i in mystr[:1] if i]You have an interval in the begening in the string " domain ontologies". So when you split it, it returns an empty string as the first index. Which is None in Python. Use strip(). mystr = c.strip(' ').split() RE: how to remove none from the for loop - buran - Feb-27-2017 As pointed out by Ofnuts in the other thread split() without argument will take care.>>> " domain ontologies".split() ['domain', 'ontologies'] RE: how to remove none from the for loop - snippsat - Feb-27-2017 Use Code tag. Code you have will not output what you have posted. RE: how to remove none from the for loop - desul - Feb-27-2017 (Feb-27-2017, 01:30 PM)desul Wrote: Dear all, RE: how to remove none from the for loop - sparkz_alot - Feb-27-2017 Just repeating what others have said: c = " domain ontologies" mystr = c.split() print(mystr[0]) print(mystr[1])
|