how to match list members in py3.x
Michael F. Stemper
michael.stemper at gmail.com
Sun Nov 25 15:16:43 EST 2018
On 25/11/2018 11.41, Richard Damon wrote:
> On 11/25/18 12:28 PM, Muhammad Rizwan wrote:
>> handle = open('file.txt')
>> newlist = list()
>> for line in handle:
>> #line.rstrip()
>> linewords = line.split()
>> print(linewords)
>>
>> for word in linewords:
>> newlist.append(word)
>> if word not in linewords:
>> continue
>>
>>
>>
>> print('new: ',newlist)
>
> The first thing I note in looking at this is that the second loop will
> run AFTER the first loop completes, not for each step of the loop,
> because you outdented the code.
>
> Also, you unconditionally add the word, and THEN check if it is in the list.
And the first thing that I note is that he checks to see if it is in
the list from which it came.
--
Michael F. Stemper
Economists have correctly predicted seven of the last three recessions.
More information about the Python-list
mailing list