【发布时间】:2012-11-27 12:31:06
【问题描述】:
我正在尝试使用以下格式创建嵌套字典:
{person1:
{tweet1 that person1 wrote: times that tweet was retweeted},
{tweet2 that person1 wrote: times that tweet was retweeted},
person2:
{tweet1 that person2 wrote: times that tweet was retweeted},...
}
我正在尝试从以下数据结构中创建它。以下是真实版本的截断版本。
rt_sources =[u'SaleskyKATU', u'johnfaye', u'@anisabartes']
retweets = [[],
[u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT',u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT', u'Stay safe #nyc #sandy http://t.co/TisObxxT'], []]
annotated_retweets = {u'Stay safe #nyc #sandy http://t.co/TisObxxT':26}
'''
Key is a tweet from set(retweets)
Value is how frequency of each key in retweets
'''
for_Nick = {person:dict(tweet_record,[annotated_tweets[tr] for tr in tweet_record])
for person,tweet_record in zip(rt_sources,retweets)}
this SO question 和 this one 似乎都不适用。
【问题讨论】:
-
请给出实际的示例数据和实际所需的输出。
-
为什么在没有关于如何改进问题的建议的情况下投反对票?
-
@JanneKarila 谢谢。我编辑了我的答案以修复
SyntaxError。 -
当前代码会发生什么?它会引发异常吗?如果是这样,请包括回溯。如果不是,那会发生什么?由于您没有提供任何示例数据,因此无法测试您的代码。
标签: python dictionary python-twitter