python - Python没有从列表中删除元素
问题描述
我有一本字典,其中包含我想问的几个问题,其中一个键从 1 到 7。我还有一个包含以下元素的列表:[1, 2, 3, 4, 5, 6, 7]
,它表示字典中使用的键,我'已将列表随机化,以便随机提出问题。但是,一旦提出问题,我想从列表中删除第一个元素,这样就不能再问了,这样最终就没有问题了(要删除的元素的实际内容每次都会有所不同),但是每当我运行我的代码时,列表的大小保持不变
def random_function():
questions = {
1: "Describe what the instruction 'BRP' does.",
2: "Describe what is meant by the term 'Open Source Software'.",
3: "What is meant by the term 'Lossy Compression'?",
4: "What is the number '55' as an 8-bit unsigned integer?",
5: "What might a printer use RAM for?",
6: "Describe the term 'firewall'.",
7: "Describe the Rapid Application Development process."
}
random_list = [1, 2, 3, 4, 5, 6, 7]
random.shuffle(random_list)
question = Label(root, bg="white", text=questions[random_list[0]], font = ("Segoe UI", 14))
question.place(x=20, y=20)
print(random_list) #just to troubleshoot
del(random_list[0])
root_win2()
def root_win2():
global question, random_list, questions
next_button = Button(text="Next Question", command=random_function, height=3, width=12)
next_button.place(x=370, y=300)
(注意先运行 root_win2() 函数,然后跳转到 random_function() 函数,然后再跳转回 root_win2() 函数等)
我在这里做错了什么吗?
解决方案
您需要保留从其中删除项目random_list
的功能之外的书籍。random_function
推荐阅读
- javascript - 将高级自定义字段添加到 OnClick JS 函数中
- r - 在 MYSQL DB 中编写随机森林模型
- javascript - 将全局基本名称/上下文添加到 React 和 npm 设置
- c# - 在特定时间创建通知
- typo3 - 添加自己的 sys_category 以使用 extbase 记录
- java - Apache Pulsar Consumer.acknowledgeAsync() 失败应该如何处理?
- laravel - 尝试在数据库中插入数据时遇到问题,LARAVEL
- javascript - 为什么循环在使用 push-shift 获取 desc 数据的最后一个索引处添加第一个值
- arrays - 排除某些列 IDL 的数组的平均值
- python - 显示 GIF 并等待按键