目标:在列表理解中创建一个条件语句,它 (1)动态测试——即,在每次迭代时——如果元素不在给定的列表中,则给定 (2) 列表本身在每次迭代时更新。
后台代码:
arr = [2, 2, 4]
l = list()
Run Code Online (Sandbox Code Playgroud)
期望的输出:
l = [2, 4]
Run Code Online (Sandbox Code Playgroud)
通过 for 循环所需的行为:
for element in arr:
if element not in l:
l.append(element)
Run Code Online (Sandbox Code Playgroud)
不正确的列表理解不会产生所需的行为:
l = [element for element in arr if element not in l]
Run Code Online (Sandbox Code Playgroud)
问题重申:如何修复列表理解以生成所需的行为,即上述所需的输出?
使用 Jekyll 启动 Github 页面。我正在关注Github Pages 文档。
执行后:
bundle exec jekyll 3.8.7 new .
返回以下错误:
fatal: 'jekyll 3.8.7' could not be found. You may need to install the jekyll-3.8.7 gem or a related gem to be able to use this subcommand..
另请注意,(a) Jekyll 3.8.7 是Github Pages的当前依赖版本,(b) 如果我尝试使用 Jekyll 4.1.0,则会返回相同的错误。
我尝试了这篇 SO 帖子中的建议-- $ bundle init, $ bundle add jekyll-- 但这并没有解决我的问题。
系统详情:
$ which ruby
/Users/vishrutarya/.rbenv/shims/ruby
$ …Run Code Online (Sandbox Code Playgroud)