【发布时间】:2021-11-29 16:03:13
【问题描述】:
程序运行并且函数工作,但我无法在输出中看到我的 docCountryList。谁能告诉我为什么?
我有这个代码
def ViewByCountry(docID,user_selection):
docCountryList=[]
for x in jfile:
if x.get('subject_doc_id') == docID:
docCountryList.append(x['visitor_country'])
if user_selection == '2a':
x = []
y = []
#Insert countries and number of occurences in two seperate lists
for k,v in Counter(docCountryList).items():
x.append(k)
y.append(v)
plt.title('Countries of Viewers')
plt.bar(range(len(y)), y, align='center')
plt.xticks(range(len(y)), x, size='small')
plt.show()
return docCountryList
在我的主要
from program import ViewByCountry
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
docID = input("Enter required document ID: ")
user_selection = input("Enter selection")
ViewByCountry(docID,user_selection)
【问题讨论】:
-
print(ViewByCountry(docID,user_selection)) -
您是否打算仅在
user_selection == '2a'时返回国家/地区列表? -
欢迎来到 Stack Overflow。您的代码缺少导入,并且不清楚这些对象的一半是多少。请编辑问题以包含"Minimal, Reproducible, Example."