我正在尝试从 python 中的随机库导入选项,但出现错误。
from tkinter import *
from itertools import accumulate
from random import choices
from string import ascii_lowercase
Run Code Online (Sandbox Code Playgroud)
我收到错误消息,文件“c:\Users\coope\Downloads\hw3.py”,第 26 行,来自随机导入选择 builtins.ImportError: cannot import name 'choices'
我需要遍历一个整数列表并确定有多少非零元素并返回这些元素。我不确定在遍历列表时是否应该使用计数器变量,我对遍历列表本身的最有效方法感兴趣。这是我到目前为止所拥有的......我是haskell的新手,所以我正在用伪代码编写其中的一些。
nonzero :: [int] -> Int
nonzero let counter = 0
if xs == 0 counter = counter + 1
Run Code Online (Sandbox Code Playgroud)