小编wal*_*elb的帖子

如何在不考虑空格和连字符的情况下换行文本

我有一个 contenteditable div,用户可以在其中输入文本。我希望文本自动换行,但不像空格或连字符的默认换行,而是像这样:

This is some t
ext that conta
ins hyphenated
 words like th
is-thing-here,
 and also spac
es.
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这个目标?

html css

62
推荐指数
3
解决办法
4431
查看次数

为什么不能像定义中那样实现定点组合器?

我正在尝试像 Curry 定义的那样实现 Y 组合器。

此代码不起作用。它会导致无限递归。

F = (lambda f: (lambda x: (1 if x == 0 else (x * (f(x-1))))))    
Y = (
    lambda f: 
    (lambda x: f(x(x)))
    (lambda x: f(x(x)))
)
Y(F)(3)
Run Code Online (Sandbox Code Playgroud)

但是,这个确实有效:

Y = (
    lambda f: 
    (lambda x: f(
        lambda v: x(x)(v)
    ))
    (lambda x: f(
        lambda v: x(x)(v)
    ))
)
Y(F)(3)
Run Code Online (Sandbox Code Playgroud)

为什么第一个不起作用,而第二个起作用?

python lambda-calculus python-3.x

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

Python 解包列表:不能使用带星号的表达式

我尝试列出以“\t”开头的所有安装点:

with open("/proc/mounts") as f:
    mountpoints = (
        [list((filter(lambda s: s.startswith("/t"), line.split(" "))))
         for line in f if
        (lambda l:
         list(filter(lambda x: x.startswith("/t"), l))
        )(line.split(" "))])
    


print(mountpoints)
#[['/tmp']]
#this is correct, however I want to remove one pair of brackets

print(*mountpoints)
#['/tmp']
#this works!

m = *mountpoints
#SyntaxError: can't use starred expression here
#but this doesn't.
Run Code Online (Sandbox Code Playgroud)

为什么最后一个作业不起作用?与 print 语句有什么区别?

感谢帮助!

python python-3.x

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

标签 统计

python ×2

python-3.x ×2

css ×1

html ×1

lambda-calculus ×1