小编Ole*_*zov的帖子

Mypy 迭代器和生成器有什么区别?

主要区别是什么?各自应该使用什么以及在哪里使用?

例如,在这个示例中,使用 - 以及迭代器和生成器似乎对我来说是合适的......但这是真的吗?

迭代器

from typing import Generator, Iterator

def fib(n: int) -> Iterator[int]:
    a :int = 0
    b :int = 1
    while a < n:
        yield a
        a, b = b, a+b

print([x for x in fib(3)])
Run Code Online (Sandbox Code Playgroud)

发电机

from typing import Generator 

def fib(n: int) -> Generator[int, None, None]:
    a :int = 0
    b :int = 1
    while a < n:
        yield a
        a, b = b, a+b

print([x for x in fib(3)])
Run Code Online (Sandbox Code Playgroud)

types python-3.x mypy

5
推荐指数
1
解决办法
2657
查看次数

性能:使用Sort实现对Slice与Sorting Type(Slice)进行排序

我正在玩一些代码挑战,发现自定义排序(排序接口的实现)比单独的切片原始结构更快.这是为什么?切片转换为类型是否做了一些megic(比如转换为指向结构的指针)?

我做了一些代码来测试我的hipotesis

package sortingexample

import (
    "sort"
    "testing"
)

// Example of struct we going to sort.

type Point struct {
    X, Y int
}

// --- Struct / Raw Data
var TestCases = []Point{
    {10, 3},
    {10, 4},
    {10, 35},
    {10, 5},
    {10, 51},
    {10, 25},
    {10, 59},
    {10, 15},
    {10, 22},
    {10, 91},
}

// Example One - Sorting Slice Directly
// somehow - slowest way to sort it.
func SortSlice(points []Point) {
    sort.Slice(points, func(i, j int) bool …
Run Code Online (Sandbox Code Playgroud)

sorting go slice

3
推荐指数
1
解决办法
347
查看次数

vscode ExtensionHost 启动上的当前工作目录

我过去做过一些主题开发,想更新它。不幸的是,我没有保存以前的launch.json内容,并且缺少在f5.

我找到的唯一选项是cwd,但它不起作用。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Extension",
            "type": "extensionHost",
            "request": "launch",
            "runtimeExecutabl5e": "${execPath}",
            "args": [
                "--extensionDevelopmentPath=${workspaceFolder}"
            ], 
        },
    ]
}
Run Code Online (Sandbox Code Playgroud)

我确信,vscode在开发新主题时,我确实使用过打开启动任务打开的文件。这就是我测试语法突出显示的方式(通过在启动时在vscode开发的扩展内打开不同的文件)...

发生了什么变化以及如何使其再次发挥作用?

visual-studio-code

2
推荐指数
1
解决办法
426
查看次数

如何将长字符串转换为短字符串,并且是可逆操作

我有一个很长的stringfrom Base64,但是它太长了,我如何将其转换为短的。我希望这是一个可逆的操作,因为我想从短的中得到长的。顺便说一句,我不想​​将这两个字符串保存到数据库中。

algorithm go

-1
推荐指数
1
解决办法
96
查看次数

标签 统计

go ×2

algorithm ×1

mypy ×1

python-3.x ×1

slice ×1

sorting ×1

types ×1

visual-studio-code ×1