AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-17573789

Eric Wang's questions

Martin Hope
Eric Wang
Asked: 2025-04-29 04:52:15 +0800 CST

根据一个父维度定义两个元素维度

  • 5

:root {
    --success: #0c0;
}

button {
    border: 2px solid;
    border-radius: 10px;
    cursor: pointer;
    margin: 1em 0.5em;
    padding: 10px 15px;
    transition: transform 1s;
}

button:active {
    transform: scale(90%);
}

button.animated {
    background-color: transparent;
    overflow: hidden;
    position: relative;
    transition: color 1s, border-color 1s, transform 0.2s;
    z-index: 1;
}

button.animated:hover {
    border-color: transparent;
}

button.animated::after {
    border: 0;
    border-radius: 50%;
    content: "";
    height: 150%;
    left: -25%;
    opacity: 0;
    position: absolute;
    top: -25%;
    transform: scale(0.1);
    transform-origin: center;
    transition: all 1s;
    width: 150%;
    z-index: -1;
}

button.animated:hover::after {
    opacity: 1;
    transform: scale(1);
}

.text,
button.animated.background::after {
    background-color: white;
}

.background,
button.animated.text:hover{
    color: white;
}

button.animated.text {
    border-color: var(--muted);
}

.success.text,
button.animated.success.background:hover {
    color: var(--success);
}

.success.background,
button.animated.success.text::after {
    background-color: var(--success);
}

button.animated.success.text:hover,
button.animated.success.background {
    border-color: var(--success);
}
<button class="animated success background">Button</button>
<button class="animated success background">Longer button</button>

上面代码片段中的按钮具有椭圆形的背景效果,当您将鼠标悬停在按钮上时,该效果就会出现。目前,椭圆的尺寸与按钮的尺寸成比例。我希望椭圆是圆形,其宽度是按钮长边的 141.4%,或者,如果不可能的话,是按钮的宽度。我该如何实现?

html
  • 2 个回答
  • 45 Views
Martin Hope
Eric Wang
Asked: 2025-03-06 02:40:45 +0800 CST

如何解析以平面列表形式呈现的嵌套结构?

  • 10

为了轻松理解我的问题,下面是一些示例输入的简化版本。

['foo', 1, 'a', 'foo', 2, 'foo', 1, 'b', 'foo', -1, 'foo', -1, "bar", 1, "c", "bar", 2, 'baz', 1, 'd', 'baz', -1, "bar", 3, "e", "bar", 4, 'qux', 1, 'stu', 1, 'f', 'stu', -1, 'qux', -1, 'bar', -1]

(我使用“stu”是因为我没有占位符名称。)

这些字符串是函数名(有点像,稍后详细说明)。函数名后面的数字指定了参数在后面函数中的位置。位置为 -1 表示函数结束。

例如,['foo',1,'a','foo',2,'b','foo',-1]应该等同于foo('a', 'b')。

嵌套时也应该有效:

['foo', 1, 'a', 'foo', 2, 'foo', 1, 'b', 'foo', -1, 'foo', -1]

应该foo('a', foo('b'))相当于

['bar', 1, 'c', 'bar', 2, 'baz', 1, 'd', 'baz', -1, 'bar', 3, 'e', 'bar', 4, 'qux', 1, 'stu', 1, 'f', 'stu',-1, 'qux', -1, 'bar', -1]

应该等同于bar('c', baz('d'), e, qux(stu('f')))。

我想要的函数应该返回一个列表。例如,

['foo', 1, 'a', 'foo', 2, 'foo', 1, 'b', 'foo', -1, 'foo', -1, 'bar', 1, 'c', 'bar', -1]

应该导致

[['foo', 'a', ['foo', 'b']], ['bar', 'c']]

现在问题已经更清楚了,但我的实际问题略有不同。列表中的所有元素都是整数。函数名称不是字符串,而是三个整数的序列。因此,['foo',1,'a','foo',2,'b','foo',-1]实际上是[1, 1, 1, 1, 104, 1, 1, 1, 2, 105, 1, 1, 1, -1]。

函数名称 ([1, 1, 1]在上例中 ) 充当字典键。字典 ( 称为constructs) 如下所示:

constructs = {
    1: {
        1: {
            1: lambda *chars : print(''.join(chr(char) for char in chars))
        }
    }
}

因此,最后,该示例应产生如下结果

[[lambda *chars : print(''.join(chr(char) for char in chars)), 104, 105]]

所有关于嵌套等的规范都应该仍然适用。我不知道如何可靠而优雅地实现这一点,请帮忙!

提前致谢。

编辑:我忘了说0总是被忽略和跳过,并且跟在0函数调用后面的 会逃避函数调用并导致它被视为参数。到目前为止,所有这些功能都在某种程度上实现了,但当同一个函数嵌套在其自身中时,它不起作用。它也是低效和不优雅的,有很多潜在的问题,所以我向 Stack Overflow 寻求帮助,编写一个更好的。请随意使用它作为起点!

编辑2:这是我迄今为止尝试的代码:

constructs = {
    1: {
        1: {
            1: print,
        }
    }
}

def parse(code: list) -> list:
    if len(code) <= 1:
        return code
    result = []
    in_function = 0
    for i, token in enumerate(code):
        if in_function > 0:
            in_function -= 1
            continue
        if token == 0:
            continue
        if result and result[-1][0][3] != -1:
            if token in constructs and code[i + 1] in constructs[token] and code[i + 2] in constructs[token][code[i + 1]]:
                if i < len(code) - 4 and code[i + 4] == 0:
                    result[-1][-1].append(token)
                else:
                    if code[i + 3] == result[-1][0][3] + 1:
                        result[-1].append([])
                    result[-1][0] = code[i:i + 4]
                    in_function = 3
            else:
                result[-1][-1].append(token)
        else:
            if token in constructs and code[i + 1] in constructs[token] and code[i + 2] in constructs[token][code[i + 1]]:
                if code[i + 3] == 1:
                    result.append([code[i:i + 4], []])
                    in_function = 3
                else:
                    raise SyntaxError(f'function {code[i:i + 3]} has no previous separator {code[i + 3] - 1}')
            else:
                raise SyntaxError(f'function {code[i:i + 3]} was not recognized')
    for i, function in enumerate(result):
        result[i][0] = constructs[result[i][0][0]][result[i][0][1]][result[i][0][2]]
        for j, argument in enumerate(result[i][1:]):
            result[i][j + 1] = parse(argument)
    return result

它适用于parse([1, 1, 1, 1, 'Hello world', 1, 1, 1, 2, 'etc', 1, 1, 1, -1])但不适合parse([1, 1, 1, 1, 1, 1, 1, 1, 'Hello world', 1, 1, 1, -1, 1, 1, 1, 2, 'etc', 1, 1, 1, -1])。

python
  • 2 个回答
  • 125 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve