[omaha] Fwd: OPUG New Question Notification

Steve Young wereapwhatwesow at gmail.com
Mon Feb 20 15:56:02 EST 2017


We have had another question on the website if anyone wants to try an
answer.

We can also use this to post questions/answers/topic details on the website
to keep them more easily available than the email list for
historical/posterity sake.

---------- Forwarded message ----------
From: WordPress <dundeemt+omaha at gmail.com>
Date: Sun, Feb 19, 2017 at 4:52 PM
Subject: OPUG New Question Notification
To: wereapwhatwesow at gmail.com, dundeemt+omaha at gmail.com


A new question was posted on Omaha Python Users Group,

has asked a question "for loops - beginner question
<http://www.omahapython.org/blog/question/for-loops-beginner-question>":
Greetings! I have recently started Python as my first computer language and
there is one part of the for loops I am having trouble with. The objective
of the code below is to turn a list [1,1,2,3,3,3,4,4,5] into a list with
only the unique elements of the first list. [1,2,3,4,5] without the use of
sets. *code:* def unique_list(g):
      x = [ ]
     * for* a* in* g:
          * if* a *not in* x:
               x.append(a)
return x   I understand what each individual part of the code does but the
part of "*for* a *in* g" is what confuses me. I know "g" is the list in
reference but what is "a"? If it is the elements in "g" how can Python tell
the difference of each element, if I had numbers and strings and symbols?
Also, the below section is confusing in the sense of what the role of "a"
is and how does it know which to append? I get that if an "a" similar to
another "a" is in the list it will not duplicate it but how does it know
which "a" to append? *code:* *if* a *not in* x:
               x.append(a)   My apologies for the long post and I hope what
I asked is understandable. Any help would be greatly appreciated!   All the
best,   Nico
View Question →
<http://www.omahapython.org/blog/question/for-loops-beginner-question>
Omaha Python Users Group - Python Users in the Omaha Metro Area


More information about the Omaha mailing list