小编lee*_*man的帖子

如何从Python列表的末尾删除“无”项

有一个列表,其中可能包含无项目。我想删除这些项目,但前提是它们出现在列表的末尾,所以:

[None, "Hello", None, "World", None, None]
# Would become:
[None, "Hello", None, "World"]
Run Code Online (Sandbox Code Playgroud)

我已经编写了一个函数,但是我不确定这是否是在python中进行处理的正确方法?:

def shrink(lst):
    # Start from the end of the list.
    i = len(lst) -1
    while i >= 0:
        if lst[i] is None:
            # Remove the item if it is None.
            lst.pop(i)
        else:
            # We want to preserve 'None' items in the middle of the list, so stop as soon as we hit something not None.
            break
        # Move through the list backwards.
        i -= 1 …
Run Code Online (Sandbox Code Playgroud)

python list

21
推荐指数
1
解决办法
1509
查看次数

C 从文字浮点数赋值

在阅读一本关于 3D 图形书的一部分时,我遇到了以下作业:

const float vertexPositions[] = {
0.75f, 0.75f, 0.0f, 1.0f,
0.75f, -0.75f, 0.0f, 1.0f,
-0.75f, -0.75f, 0.0f, 1.0f,
};
Run Code Online (Sandbox Code Playgroud)

为什么需要 f 后缀?不能从变量的类型确定文字的类型吗?我相信没有 f 浮点文字被解释为双打,但为什么当数组显然是 float 类型时?

c floating-point assign

4
推荐指数
1
解决办法
1074
查看次数

标签 统计

assign ×1

c ×1

floating-point ×1

list ×1

python ×1