class A:
   id = ""
   fld = []
   def __init__(self, id):
      self.id = id
                                                                                                                                                                               
                                                                                                                                                                               
def method(inp):
   a = A("a")
   b = A("b")
   c = A("c")
   a.fld.append("Histogram")
   a.fld.append("Dendogram")
   b.fld.append("Milligram")
   b.fld.append("Pictogram")
   c.fld.append("Pro--gram")
   c.fld.append("Dodge-ram")
   print a.fld
   print b.fld
   print c.fld
   inp.append(a)
   inp.append(c)
   inp.append(b)
                                                                                                                                                                               
#__main__                                                                                                                                                          
inp = []
method(inp)
                                                                                                                                                                               
for ins in inp:
    print "-----> " + ins.id
    for fl in ins.fld:
        print fl

Trying to understand why 18.print prints all the 12_17.appends
I am completely new and practising. Pls help!

['Histogram', 'Dendogram', 'Milligram', 'Pictogram', 'Pro--gram', 'Dodge-ram']
['Histogram', 'Dendogram', 'Milligram', 'Pictogram', 'Pro--gram', 'Dodge-ram']
['Histogram', 'Dendogram', 'Milligram', 'Pictogram', 'Pro--gram', 'Dodge-ram']
-----> a
Histogram
Dendogram
Milligram
Pictogram
Pro--gram
Dodge-ram
-----> c
Histogram
Dendogram
Milligram
Pictogram
Pro--gram
Dodge-ram
-----> b
Histogram
Dendogram
Milligram
Pictogram
Pro--gram
Dodge-ram

The way your class is written the list 'fld' is global to all instances of the class. You need to write your class this way ...

class A:
   id = ""
   #fld = []
   def __init__(self, id):
       self.fld = []
       self.id = id
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.