how to match list members in py3.x

Muhammad Rizwan rizwan.ned.ee at gmail.com
Sun Nov 25 12:28:05 EST 2018


On Sunday, 25 November 2018 12:14:37 UTC-5, Joel Goldstick  wrote:
> On Sun, Nov 25, 2018 at 11:51 AM Muhammad Rizwan
> <> wrote:
> >
> > On Sunday, 25 November 2018 11:41:56 UTC-5, Joel Goldstick  wrote:
> > > On Sun, Nov 25, 2018 at 11:36 AM Muhammad Rizwan
> > > <> wrote:
> > > >
> > > > IF YOU CAN'T HELP BETTER IGNORE THE POST AND DON'T TRY TO BE A SMART ASS.
> > > >
> > > >
> > > > --
> > > > https://mail.python.org/mailman/listinfo/python-list
> > >
> > > That isn't a productive way to get assistance.   It is true that
> > > people here are often very knowledgeable to help with python problems,
> > > but as a rule,  doing someone's homework isn't something people like
> > > to do.
> > >
> > > On to your problem.  You should understand lists and sets, and for
> > > loops.  Try some code and come back with what you have.  Then you will
> > > get help to go further
> > >
> > > --
> > > Joel Goldstick
> > > http://joelgoldstick.com/blog
> > > http://cc-baseballstats.info/stats/birthdays
> >
> > I have been trying since morning but it doesn't work.
> 
> The way to use this mailing list is to explain your problem, which you
> have done.  Then, show the code you have written with the results it
> produces.  Its good to include the operating system you are using
> (windows, linux, osx), and if your code produces a traceback, copy and
> paste it here.
> 
> Its common to be frustrated learning to write and writing code, but if
> you want help you have to show something for others to help you with
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> -- 
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays

Below is my approach which I am sure is wrong somewhere and it doesn't work the way expected, the append doesn't do anything in my code nor does it returns any traceback all i see is a empty list printed at the end, I am using win10 x64 python 3.x atom-editor. Please take a look if you can tell me what am I doing wrong here. I want to check each list word by word if the word is not repeated in the same list it should be appended to a 'newlist'. Thanks in advance

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)



More information about the Python-list mailing list