无论如何我可以在python中生成四个字符串的无限列表

问题描述

我有一个包含四种颜色的列表,我想生成一个无限列表,这样当我输入随机索引时,它会显示在该位置找到的颜色

解决方法

number = int(input('write your index here:'))
color = ['b','k','g','y']
chosen_color = color[number%len(color)]
print(chosen_color)

输出:

write your index here: 98435164
b