title: AttributeError: 'float' object has no attribute 'append' - Python Dictionary
body: <p>I am attempting to create a new dictionary which will list the species of a tree as well as the DBH for that species. There will be multiple DBH's for each species. It pulls this information from a text file. </p>
  
  <p>The part that creates the first dictionary is working (lists the species and the number for each), but I cannot get it to append the DBH's for each species. I continue to get the error AttributeError: 'float' object has no attribute 'append'. I have searched and searched and tried multiple ways, but cannot get this to work.</p>
  
  <pre><code>import string, os.path, os, sys
  
  
  filepath = "C:\\temp\\rdu_forest1.txt"
  data=[]
  #Open the text file
  myfile=open(filepath,'r')
  #Read the text file
  myfile.readline() #read the field name line
  row = myfile.readline()
  count = 0
  while row:
      myline = row.split('\t') #Creat a list of the values in this row.  Columns are tab separated.
      #Reads a file with columns: Block Plot  Species DBH MerchHeight
      data.append([float(myline[0]),float(myline[1]),myline[2].rstrip(),float(myline[3].rstrip())]) 
      #rstrip removes white space from the right side
      count = count + 1
      row = myfile.readline()
  myfile.close()
  mydict={}
  
  mydict2={} #Create an emyty mydict2 here  *********
  
  for row in data:  # for each row
      # create or update a dictionary entry with the current count for that species
      species = row[2]#Species is the third entry in the file
      DBH = row[3] #DBH is the fourth entry in the file 
      if mydict.has_key(species):  #if a dictionary entry already exists for this species
          #Update dict for this species
          cur_entry = mydict[species]
          cur_entry = int(cur_entry)+1
          mydict[species] = cur_entry
  
          #update mydict2 here  *********
          mydict2[species].append(DBH)
  
      else:#This is the first dictionary entry for this species
          #Create new dict entry with sums and count for this species
          mydict[species]=1
          mydict2[species]=DBH #Add a new entry to mydict2 here  *********
  
  print mydict
  </code></pre>
  
  <p>Here is the TraceBack</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
      exec codeObject in __main__.__dict__
    File "E:\Python\16\dictionary.py", line 40, in &lt;module&gt;
      mydict2[species].append(DBH)
  AttributeError: 'float' object has no attribute 'append'
  </code></pre>