I have read all the script from default dict and all the posts on here. I believe my syntax is correct.
influenceDict = defaultdict(list)
to fill with all tags from all tweets
Later, I am appending ALOT of float values, 1000+ list entries for a majority of dictionary keys. I get my error on line 47, specified below.
def addInfluenceScores(hashtagArr,numFollowers,numRetweets, influenceDict):
influenceScore = float(0)
if numFollowers == 0 and numRetweets != 0:
influenceScore = numRetweets + 1
elif numFollowers == 0 and numRetweets == 0:
influenceScore = 0
else:
influenceScore = numRetweets / numFollowers
print "Adding influence score %f to individual hashtags" % (influenceScore)
for tag in hashtagArr:
tID = tag2id_map[tag]
print "Appending ",tID,tag
# if not influenceDict.has_key(tID):
# influenceDict[tID] = list()
# influenceDict[tID].append(influenceScore)
# else:
# influenceDict[tID].append(influenceScore)
influenceDict[tID].append(influenceScore) **#LINE 47 I GET THE ERROR HERE**
for i in range(len(hashtagArr)):
for j in range(i+1, len(hashtagArr)):
tID1 = tag2id_map[hashtagArr[i]]
tID2 = tag2id_map[hashtagArr[j]]
if(tID2 < tID1): #ensure alpha order to avoid duplicating (a,b) and (b,a)
temp = tID1
tID1 = tID2
tID2 = temp
print "Appending ",tID1, hashtagArr[j],tID2,hashtagArr[i]
# if not influenceDict.has_key((tID1, tID2)):
# influenceDict[(tID1, tID2)] = list()
# influenceDict[(tID1, tID2)].append(influenceScore)
# else:
# influenceDict[(tID1, tID2)].append(influenceScore)
influenceDict[(tID1, tID2)].append(influenceScore)
The program runs for a while, and it actually does append values (or so I think) and then I get this error:
Traceback (most recent call last):
File "./scripts/make_id2_influencescore_maps.py", line 158, in <module
processTweets(tweets, influenceDict)
File "./scripts/make_id2_influencescore_maps.py", line 127, in processTweets
addInfluenceScores(hashtags, numFollowers,numRetweets, influenceDict)
File "./scripts/make_id2_influencescore_maps.py", line 47, in addInfluenceScores
influenceDict[tID].append(influenceScore)
AttributeError: 'float' object has no attribute 'append'
I am thinking that the list is just maxed out in memory. Maybe you guys can see something I don't. I am trying to loop through a file of tweets and for everytime I see the hashtag I want to append a score to the list associated with it. That way I can just take the average of all the scores in the list when I am completely done reading the file. Thanks ahead.