小编P. *_*lor的帖子

Python - Jupyter 无法识别 Unix 命令

我已经为课程安装了 Git Bash、python 3.6 和 Anaconda,这要求我在 Jupyter 中使用 Unix 命令,例如 !ls、!cat、!head 等。但是,对于这些命令中的每一个,我得到(例如):

'ls' 不是内部或外部命令,也不是可运行的程序或批处理文件。

我使用的是 Windows 10。我该怎么做才能继续学习课程?谢谢!

python windows git jupyter

5
推荐指数
2
解决办法
5495
查看次数

HTML和CSS - 布局问题(使用grid&flexbox)

Codepen:https://codepen.io/pprunesquallor/pen/qKxvrX

我是初学者,玩网格和flexbox.

我想文章元素(黄色)的高度只有就像只要文本需要(所以在这种情况下,CCA一半长),因此aside元素(灰色)应根据相同的高度文章的高度,可滚动.

先感谢您!!

html, body {
    height: 100%;
}

body {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: 
    "header"
    "main"
    "footer";
  align-items: stretch;
}

header {
  grid-area: header;
  display: flex;
  flex-direction: column;
  background-color: lime;
}

header > h1 {
  margin: 0;
  background-color: brown;
}

nav {
    display: flex;
    flex-direction: row;
    background-color: orange;
}

main {
  grid-area: main;
  display: flex;
  flex-direction: row;
  background-color: red;
}

article {
  background-color: yellow;
}

aside {
  width: 50%;
  overflow: auto;
  overflow-y: scroll;
  background-color: grey; …
Run Code Online (Sandbox Code Playgroud)

html css css3 flexbox css-grid

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

python - 返回没有公因数的数字

问题如下:

创建一个接受 2 个输入、一个数字n和一个列表的函数lst。该函数应返回一个列表,其中lst包含与n(1 除外)没有共同因子的所有数字。n 和 中的所有数字 lst均为大于或等于 0 的正整数。

我的尝试

def no_common_factors (n, lst):

    def uf(n):  #get a set of factors
        factors = []
        i = 2
        while n > 1: 
            if n % i == 0: 
                factors += [i]
                n = n / i
            else: 
                i += 1
        return set(factors)

    factors_n = uf(n)
    no_common = []

    for i in range(0, len(lst)): 
        factors_i = uf(i)
        if factors_n.isdisjoint(factors_i): 
            no_common += [lst[i]] …
Run Code Online (Sandbox Code Playgroud)

python

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

递归表达式解释?(蟒蛇)

我一直在做一些编码练习并遇到了这个我很想理解的解决方案.

问题(我重写了一下,所以不容易搜索):

编写一个接受正参数n的函数,并返回在达到单个数字之前必须将n中的数字相乘的次数.例如:

 f(29) => 2  # Because 2*9 = 18, 1*8 = 8, 
                       # and 8 has only one digit.

 f(777) => 4 # Because 7*7*7 = 343, 3*4*3 = 36,
                       # 3*6 = 18, and finally 1*8 = 8.

 f(5) => 0   # Because 5 is already a one-digit number.
Run Code Online (Sandbox Code Playgroud)

某人的解决方案:

from operator import mul
def f(n):
    return 0 if n<=9 else f(reduce(mul, [int(i) for i in str(n)], 1))+1
Run Code Online (Sandbox Code Playgroud)

我不明白的是表达式末尾的"+1"是如何工作的.对不起,我无法更准确地标题,但我不知道这叫什么.

谢谢!

python recursion

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

python - 使用键函数对序列进行排序

我不清楚以下内容是如何工作的:

In [1]: student_tuples = [('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10)]
In [2]: sorted(student_tuples, key=lambda student: student[2])
Out [2]: [('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)] # sort by age
Run Code Online (Sandbox Code Playgroud)

但,

In [3]: st = lambda student: student[2]
In [4]: st(student_tuples)
Out [4]: ('dave', 'B', 10)
Run Code Online (Sandbox Code Playgroud)

为什么[2]前一个示例中的 指的是各个元组的索引,而在 lambda 函数中它返回列表中的第二个元组?

python list

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

TypeError:string.split不是函数

我正在解决运动问题。在Visual Studio中解决了它(起作用),将解决方案复制到浏览器(Codewars挑战),并返回以下错误:

TypeError: string.split is not a function
   at bulk
    at _
    at begin
    at it
        at /runner/frameworks/javascript/cw-2.js:159:11
    at Promise._execute
    at Promise._resolveFromExecutor
    at new Promise
    at Object.describe
            at Object.handleError
        at ContextifyScript.Script.runInThisContext
    at Object.exports.runInThisContext
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

TypeError: string.split is not a function
   at bulk
    at _
    at begin
    at it
        at /runner/frameworks/javascript/cw-2.js:159:11
    at Promise._execute
    at Promise._resolveFromExecutor
    at new Promise
    at Object.describe
            at Object.handleError
        at ContextifyScript.Script.runInThisContext
    at Object.exports.runInThisContext
Run Code Online (Sandbox Code Playgroud)

我想我曾经有一个类似的问题,可以通过制作this.split()解决,但现在不起作用(Codewars不接受,返回“ TypeError:this.split不是函数”)。谢谢!

javascript typeerror

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

matplotlib ylim &amp; TypeError:“float”对象不可调用

我有这个嵌套列表:

acc = [[3, 0.95804195804195802], [4, 0.965034965034965], [5, 0.97202797202797198], [6, 0.97202797202797198]]
Run Code Online (Sandbox Code Playgroud)

这段代码应该绘制这些值并将 y 轴的边界设置为 95 和 100:

import matplotlib.pyplot as plt

x_ = [x[0] for x in acc]
y_ = [x[1] for x in acc]

plt.figure(figsize=(8,6))
plt.scatter(x_, y_)
plt.ylim((95, 100))
plt.show()
Run Code Online (Sandbox Code Playgroud)

但我收到此错误,我不明白为什么:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-193-5a9016a37585> in <module>()
     19 plt.figure(figsize=(8,6))
     20 plt.scatter(x_, y_)
---> 21 plt.ylim((95, 98))
     22 plt.show()

TypeError: 'float' object is not callable
Run Code Online (Sandbox Code Playgroud)

python plot matplotlib typeerror

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

标签 统计

python ×5

typeerror ×2

css ×1

css-grid ×1

css3 ×1

flexbox ×1

git ×1

html ×1

javascript ×1

jupyter ×1

list ×1

matplotlib ×1

plot ×1

recursion ×1

windows ×1