写给空气的情书

文章 评论 浏览 31

写给空气的情书 2025-02-21 01:20:46

我认为,如果您以下方式查看(请继续阅读),您会理解并记住python字符串切片符号。

让我们使用以下字符串...

azString = "abcdefghijklmnopqrstuvwxyz"

的人,您可以使用符号 azstring [x:y]

对于那些不知道 编程语言,这是常识被妥协的时候。什么是X和Y?

我不得不坐下来运行几种场景,以寻求一种记忆技术,这将帮助我记住x和y是什么,并在第一次尝试时可以正确切片串。

我的结论是,X和Y应该被视为我们想要额外的弦的边界索引。因此,我们应该将表达式视为 azstring [index1,index2] ,甚至更清晰,如 azstring [index_of_first_character,index_after_after_the_last_character]

这是一个示例的可视化...

Letters   a b c d e f g h i j ...
         ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
             ┊           ┊
Indexes  0 1 2 3 4 5 6 7 8 9 ...
             ┊           ┊
cdefgh    index1       index2

因此,您要做的就是将index1和index2设置为围绕所需子字符串的值。例如,要获取子字符串“ cdefgh”,您可以使用 azstring [2:8] ,因为“ C”左侧的索引是2,而一个索引在正确的大小上”。 h“是8。

请记住,我们正在设定边界。 将一些括号放置在这样的位置的位置

...

这些边界是您可以 很容易记住。

In my opinion, you will understand and memorize better the Python string slicing notation if you look at it the following way (read on).

Let's work with the following string ...

azString = "abcdefghijklmnopqrstuvwxyz"

For those who don't know, you can create any substring from azString using the notation azString[x:y]

Coming from other programming languages, that's when the common sense gets compromised. What are x and y?

I had to sit down and run several scenarios in my quest for a memorization technique that will help me remember what x and y are and help me slice strings properly at the first attempt.

My conclusion is that x and y should be seen as the boundary indexes that are surrounding the strings that we want to extra. So we should see the expression as azString[index1, index2] or even more clearer as azString[index_of_first_character, index_after_the_last_character].

Here is an example visualization of that ...

Letters   a b c d e f g h i j ...
         ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
             ┊           ┊
Indexes  0 1 2 3 4 5 6 7 8 9 ...
             ┊           ┊
cdefgh    index1       index2

So all you have to do is setting index1 and index2 to the values that will surround the desired substring. For instance, to get the substring "cdefgh", you can use azString[2:8], because the index on the left side of "c" is 2 and the one on the right size of "h" is 8.

Remember that we are setting the boundaries. And those boundaries are the positions where you could place some brackets that will be wrapped around the substring like this ...

a b [ c d e f g h ] i j

That trick works all the time and is easy to memorize.

Python中的切片如何工作

写给空气的情书 2025-02-20 20:25:25

这是一种简单的功能通用方法。使用数组指定排序订单。预先减去以指定降序。

var homes = [
    {"h_id":"3", "city":"Dallas", "state":"TX","zip":"75201","price":"162500"},
    {"h_id":"4","city":"Bevery Hills", "state":"CA", "zip":"90210", "price":"319250"},
    {"h_id":"6", "city":"Dallas", "state":"TX", "zip":"75000", "price":"556699"},
    {"h_id":"5", "city":"New York", "state":"NY", "zip":"00010", "price":"962500"}
    ];

homes.sort(fieldSorter(['city', '-price']));
// homes.sort(fieldSorter(['zip', '-state', 'price'])); // alternative

function fieldSorter(fields) {
    return function (a, b) {
        return fields
            .map(function (o) {
                var dir = 1;
                if (o[0] === '-') {
                   dir = -1;
                   o=o.substring(1);
                }
                if (a[o] > b[o]) return dir;
                if (a[o] < b[o]) return -(dir);
                return 0;
            })
            .reduce(function firstNonZeroValue (p,n) {
                return p ? p : n;
            }, 0);
    };
}

编辑:在ES6中,它甚至更短!

"use strict";
const fieldSorter = (fields) => (a, b) => fields.map(o => {
    let dir = 1;
    if (o[0] === '-') { dir = -1; o=o.substring(1); }
    return a[o] > b[o] ? dir : a[o] < b[o] ? -(dir) : 0;
}).reduce((p, n) => p ? p : n, 0);

const homes = [{"h_id":"3", "city":"Dallas", "state":"TX","zip":"75201","price":162500},     {"h_id":"4","city":"Bevery Hills", "state":"CA", "zip":"90210", "price":319250},{"h_id":"6", "city":"Dallas", "state":"TX", "zip":"75000", "price":556699},{"h_id":"5", "city":"New York", "state":"NY", "zip":"00010", "price":962500}];
const sortedHomes = homes.sort(fieldSorter(['state', '-price']));

document.write('<pre>' + JSON.stringify(sortedHomes, null, '\t') + '</pre>')

Here is a simple functional generic approach. Specify sort order using array. Prepend minus to specify descending order.

var homes = [
    {"h_id":"3", "city":"Dallas", "state":"TX","zip":"75201","price":"162500"},
    {"h_id":"4","city":"Bevery Hills", "state":"CA", "zip":"90210", "price":"319250"},
    {"h_id":"6", "city":"Dallas", "state":"TX", "zip":"75000", "price":"556699"},
    {"h_id":"5", "city":"New York", "state":"NY", "zip":"00010", "price":"962500"}
    ];

homes.sort(fieldSorter(['city', '-price']));
// homes.sort(fieldSorter(['zip', '-state', 'price'])); // alternative

function fieldSorter(fields) {
    return function (a, b) {
        return fields
            .map(function (o) {
                var dir = 1;
                if (o[0] === '-') {
                   dir = -1;
                   o=o.substring(1);
                }
                if (a[o] > b[o]) return dir;
                if (a[o] < b[o]) return -(dir);
                return 0;
            })
            .reduce(function firstNonZeroValue (p,n) {
                return p ? p : n;
            }, 0);
    };
}

Edit: in ES6 it's even shorter!

"use strict";
const fieldSorter = (fields) => (a, b) => fields.map(o => {
    let dir = 1;
    if (o[0] === '-') { dir = -1; o=o.substring(1); }
    return a[o] > b[o] ? dir : a[o] < b[o] ? -(dir) : 0;
}).reduce((p, n) => p ? p : n, 0);

const homes = [{"h_id":"3", "city":"Dallas", "state":"TX","zip":"75201","price":162500},     {"h_id":"4","city":"Bevery Hills", "state":"CA", "zip":"90210", "price":319250},{"h_id":"6", "city":"Dallas", "state":"TX", "zip":"75000", "price":556699},{"h_id":"5", "city":"New York", "state":"NY", "zip":"00010", "price":962500}];
const sortedHomes = homes.sort(fieldSorter(['state', '-price']));

document.write('<pre>' + JSON.stringify(sortedHomes, null, '\t') + '</pre>')

如何通过多个字段对对象进行排序?

写给空气的情书 2025-02-20 13:22:46

您还可以使用以下方式启动Vite Server:

$ npm run dev -- --host

将 - 主机标志传递到Vite命令行。

您会看到以下输出:(

vite v2.7.9 dev server running at:

  > Local:    http://localhost:3000/
  > Network:  http://192.168.4.68:3000/

  ready in 237ms.

我正在运行一个虚拟盒VM-但我认为这也适用于这里。)

You can also start your vite server with:

$ npm run dev -- --host

This passes the --host flag to the vite command line.

You will see output like:

vite v2.7.9 dev server running at:

  > Local:    http://localhost:3000/
  > Network:  http://192.168.4.68:3000/

  ready in 237ms.

(I'm running a VirtualBox VM - but I think this applies here as well.)

在Docker容器中运行Vite Dev服务器

写给空气的情书 2025-02-20 03:01:38

给定,假设目标是从字符串中提取数字:

          A         B                      C
0   7.3\N\P   nan\J\N               12.4\A\I
1   nan\T\Z   nan\A\G               13.3\H\Z
2  11.0\R\Z  10.8\F\U  8.200000000000001\B\W

做:

cols = ['A', 'B', 'C']
for col in cols:
    df[col] = df[col].str.extract('(\d*\.\d*)').astype(float)

输出:

      A     B     C
0   7.3   NaN  12.4
1   NaN   NaN  13.3
2  11.0  10.8   8.2

Given, assuming the goal is to extract numbers from the strings:

          A         B                      C
0   7.3\N\P   nan\J\N               12.4\A\I
1   nan\T\Z   nan\A\G               13.3\H\Z
2  11.0\R\Z  10.8\F\U  8.200000000000001\B\W

Doing:

cols = ['A', 'B', 'C']
for col in cols:
    df[col] = df[col].str.extract('(\d*\.\d*)').astype(float)

Output:

      A     B     C
0   7.3   NaN  12.4
1   NaN   NaN  13.3
2  11.0  10.8   8.2

数据框列清洁

写给空气的情书 2025-02-20 02:42:49

您可以在所有行数据中移动并检查data_start是预设启动重复的,并且在存在日期时,您可以退出循环
谢谢

you can move in all row data and check data_start is preset start duplicated and when present the date_end can you exit the loop
Thanks

熊猫在2个日期之间重复数据

写给空气的情书 2025-02-19 17:54:13

有几个问题需要解决,我将专注于想法,而不是此答案中的准确代码。

通过名称找到函数

您可以在功能名称和函数指针之间创建 MAP ,因此您将在函数名称和函数指针之间具有直接的链接。

参数的数量

您还可以按功能指针/函数名称存储参数的数量,因此您可以轻松地调用这些函数。您的解释器会拿一个字符串,并由某些分离器分开。

主要思想

如果您在功能的名称和函数本身之间有地图,那么您可以做这样的事情:

myMap["add"](2, 3);

There are several problems to tackle with and I will focus on ideas rather than exact code in this answer.

Finding a function by name

You can create a Map between function names and function pointers, so you will have a direct link between function names and function pointers.

Numbers of parameters

You could also store the number of parameters by function pointer/function name, so you will have an easy time calling those functions. Your interpreter would take a single string and split it by some separator.

Main idea

If you have a map between the name of the functions and the functions themselves, then you can do something like this:

myMap["add"](2, 3);

C&#x2B;&#x2B;口译员有一个内置的图书馆

写给空气的情书 2025-02-19 13:44:11

不返回任何内容(它具有 void 返回类型)。您需要像

while (listo.Count > 0)
{
    Console.WriteLine(listo[0]);
    listo.RemoveAt(0);
}

这样删除之前获取第一个元素,请考虑使用 stack&lt; t&gt; 而不是 list&lt; t&gt; as @yassinmi指出。

List<T>.RemoveAt(index) does not return anything (it has void return type). You will need to get the first element before removing it like

while (listo.Count > 0)
{
    Console.WriteLine(listo[0]);
    listo.RemoveAt(0);
}

That said, consider using Stack<T> instead of List<T> as @yassinmi pointed out.

C#:从列表中删除项目&lt; gt; ...并且该项目不被识别为字符串?

写给空气的情书 2025-02-19 11:52:41

您可以使用下部()或upper()。请检查以下答案:

 if order.lower()=="milktea":
       print(flvrs)
       laht.append(order)
       break

 if order.upper()=="MILKTEA":
       print(flvrs)
       laht.append(order)
       break

You can use either lower() or upper(). Please check the following answer:

 if order.lower()=="milktea":
       print(flvrs)
       laht.append(order)
       break

OR

 if order.upper()=="MILKTEA":
       print(flvrs)
       laht.append(order)
       break

我该如何强迫它只能绳子

写给空气的情书 2025-02-19 06:48:11

首先检查您的%userProfile%\。bashrc %userProfile%\。配置文件,因为%userProfile%是默认路径,通过bash会话作为 $ home

如果其中有任何 CD 命令,则可以解释初始错误消息。

进行回声 $ PATH 检查您的路径。
BASH会话应从Windows用户/系统环境变量继承%路径%,因此请确保 npm 首先从CMD起作用,然后重新启动VSCODE并再次打开终端。

Check first the content of your %USERPROFILE%\.bashrc or %USERPROFILE%\.profile, since %USERPROFILE% is the default path considered by a bash session as its $HOME.

If there are any cd command in those, that would explain the initial error message.

Do an echo $PATH to check your PATH.
A bash session should inherit the %PATH% from your Windows user/system environment variable, so make sure npm works from a CMD first, then relaunch VSCode and open a terminal again.

Bash:CD:E:\ Immabeme解决方案:没有此类文件或目录

写给空气的情书 2025-02-18 17:31:50
  • 诸如“在解析值时遇到的意外角色:'&lt;'。路径'',第0行,位置0。几乎总是JSON解析错误。

  • 发生它的最常见原因是当被序列化的字符串实际上不是有效的json时。

  • 还检查包含JSON字符串的文件是否具有[BOM-字节订单标记]。尝试删除BOM以解决错误。

  • Errors like "Unexpected character encountered while parsing value: '<'. Path '', line 0, position 0." are almost invariably JSON parse errors.

  • The most common reason for it to occur is when the string being deserialized is not actually valid JSON.

  • Also check if the file containing JSON string had [BOM - Byte Order Mark]. Try and remove the BOM to resolve the error.

当代码部署到Azure函数应用程序时,无法从第三方API获取HTTP响应,在调试模式下工作正常

写给空气的情书 2025-02-18 17:03:05

在模板中,您可以声明字体面,但不会将其应用于页面内容。

您只需要声明应该使用字体:

body {font-family: 'PingFang SC Regular';}

另外,您无需在模板中使用@font-face ,因为您已将字体添加到渲染器中(使用 resolver.addfont )。

以下HTML应该很好:

<html>
    <head>
        <style>
            body {font-family: 'PingFang SC Regular';}
        </style>
    </head>
    <body>
        <h3>啊啊啊啊啊啊</h3>
    </body>
</html>

In your template, you declare the font-face, but you don't apply it to the content of the page.

You just have to declare that the font should be used:

body {font-family: 'PingFang SC Regular';}

Also, you don't need to use @font-face in the template, as you have added the font to the renderer (using resolver.addFont).

The following HTML should work fine:

<html>
    <head>
        <style>
            body {font-family: 'PingFang SC Regular';}
        </style>
    </head>
    <body>
        <h3>啊啊啊啊啊啊</h3>
    </body>
</html>

UTF-8字符未在HTML模板中通过飞碟和胸腺产生的PDF中显示

写给空气的情书 2025-02-18 14:01:23

问题在这里:

如果(!res.statustext ===“ ok”)

您必须使用!== 或!= (第一个是使用数据类型的平等检查,第二个是相等性检查。

if (res.statusText != "OK")
{
  return setServerError(true);
}

The issue is here:

if (!res.statusText === "OK")

You have to use !== or != ( first one is equality check with datatype and second one is equality check. So the condition will be like:

if (res.statusText != "OK")
{
  return setServerError(true);
}

SetState一旦设置再次更改

写给空气的情书 2025-02-18 02:37:06

你可以做这样的事情

const bin = 0.1

const elaborate = (data, bin) => 
Array.from({length:Math.ceil(1 / bin)}, (_, i) => Number((bin * i).toFixed(3)))
.map(start => {
  const inRange = data.filter(({b}) => b >= start && b < start + bin)
  return {
  "CountOfA": inRange.length,
  "labelOfB": `${start.toFixed(2)}-${(start + bin).toFixed(2)}`,
  "sumOfC": inRange.reduce((res, el) => res + el.c, 0),
  "sumOfD": inRange.reduce((res, el) => res + el.d, 0),
}}).filter(d => d.CountOfA > 0)




const data = [{
    a: 0,
    b: 0.75,
    c: 0,
    d: 0
  },
  {
    a: 1,
    b: 0.88,
    c: 0,
    d: 0
  },
  {
    a: 2,
    b: 0.38,
    c: 0,
    d: 1
  },
  {
    a: 3,
    b: 0.7,
    c: 1,
    d: 1
  },
  {
    a: 4,
    b: 0.93,
    c: 1,
    d: 0
  }
];

console.log(elaborate(data, bin))
console.log(elaborate(data, 0.05))
console.log(elaborate(data, 0.2))

you can do something like this

const bin = 0.1

const elaborate = (data, bin) => 
Array.from({length:Math.ceil(1 / bin)}, (_, i) => Number((bin * i).toFixed(3)))
.map(start => {
  const inRange = data.filter(({b}) => b >= start && b < start + bin)
  return {
  "CountOfA": inRange.length,
  "labelOfB": `${start.toFixed(2)}-${(start + bin).toFixed(2)}`,
  "sumOfC": inRange.reduce((res, el) => res + el.c, 0),
  "sumOfD": inRange.reduce((res, el) => res + el.d, 0),
}}).filter(d => d.CountOfA > 0)




const data = [{
    a: 0,
    b: 0.75,
    c: 0,
    d: 0
  },
  {
    a: 1,
    b: 0.88,
    c: 0,
    d: 0
  },
  {
    a: 2,
    b: 0.38,
    c: 0,
    d: 1
  },
  {
    a: 3,
    b: 0.7,
    c: 1,
    d: 1
  },
  {
    a: 4,
    b: 0.93,
    c: 1,
    d: 0
  }
];

console.log(elaborate(data, bin))
console.log(elaborate(data, 0.05))
console.log(elaborate(data, 0.2))

如何根据使数字隔离在ReactJ中的范围内的数字创建新数组

写给空气的情书 2025-02-17 10:04:50

我的游戏很晚,但是我可以提供一些贡献,这些贡献在几种感觉上可能更优雅:

def partitions(n, m = None):
  """Partition n with a maximum part size of m. Yield non-increasing
  lists in decreasing lexicographic order. The default for m is
  effectively n, so the second argument is not needed to create the
  generator unless you do want to limit part sizes.
  """
  if m is None or m >= n: yield [n]
  for f in range(n-1 if (m is None or m >= n) else m, 0, -1):
    for p in partitions(n-f, f): yield [f] + p

只有3行代码。以词典形式产生它们。可选地允许强加最大零件大小。

我在上面的分区上也有一个给定数量数量的分区的变化:

def sized_partitions(n, k, m = None):
  """Partition n into k parts with a max part of m.
  Yield non-increasing lists.  m not needed to create generator.
  """
  if k == 1:
    yield [n]
    return
  for f in range(n-k+1 if (m is None or m > n-k+1) else m, (n-1)//k, -1): 
    for p in sized_partitions(n-f, k-1, f): yield [f] + p

撰写上述内容后,我遇到了大约5年前创建的解决方案,但我已经忘记了。除最大零件尺寸外,该功能还提供了最大长度(与特定长度相反)的附加功能。 FWIW:

def partitions(sum, max_val=100000, max_len=100000):
    """ generator of partitions of sum with limits on values and length """
    # Yields lists in decreasing lexicographical order. 
    # To get any length, omit 3rd arg.
    # To get all partitions, omit 2nd and 3rd args. 

    if sum <= max_val:       # Can start with a singleton.
        yield [sum]

    # Must have first*max_len >= sum; i.e. first >= sum/max_len.
    for first in range(min(sum-1, max_val), max(0, (sum-1)//max_len), -1):
        for p in partitions(sum-first, first, max_len-1):
            yield [first]+p

I'm a bit late to the game, but I can offer a contribution which might qualify as more elegant in a few senses:

def partitions(n, m = None):
  """Partition n with a maximum part size of m. Yield non-increasing
  lists in decreasing lexicographic order. The default for m is
  effectively n, so the second argument is not needed to create the
  generator unless you do want to limit part sizes.
  """
  if m is None or m >= n: yield [n]
  for f in range(n-1 if (m is None or m >= n) else m, 0, -1):
    for p in partitions(n-f, f): yield [f] + p

Only 3 lines of code. Yields them in lexicographic order. Optionally allows imposition of a maximum part size.

I also have a variation on the above for partitions with a given number of parts:

def sized_partitions(n, k, m = None):
  """Partition n into k parts with a max part of m.
  Yield non-increasing lists.  m not needed to create generator.
  """
  if k == 1:
    yield [n]
    return
  for f in range(n-k+1 if (m is None or m > n-k+1) else m, (n-1)//k, -1): 
    for p in sized_partitions(n-f, k-1, f): yield [f] + p

After composing the above, I ran across a solution I had created almost 5 years ago, but which I had forgotten about. Besides a maximum part size, this one offers the additional feature that you can impose a maximum length (as opposed to a specific length). FWIW:

def partitions(sum, max_val=100000, max_len=100000):
    """ generator of partitions of sum with limits on values and length """
    # Yields lists in decreasing lexicographical order. 
    # To get any length, omit 3rd arg.
    # To get all partitions, omit 2nd and 3rd args. 

    if sum <= max_val:       # Can start with a singleton.
        yield [sum]

    # Must have first*max_len >= sum; i.e. first >= sum/max_len.
    for first in range(min(sum-1, max_val), max(0, (sum-1)//max_len), -1):
        for p in partitions(sum-first, first, max_len-1):
            yield [first]+p

优雅的Python代码用于整数分区

写给空气的情书 2025-02-17 09:41:54

命令有同样的问题:
nano〜/.ssh/nameyourkey.pub
因为在终端中不要显示钥匙的某些行。

解决方案:
用命令猫导出密钥:

cat ~/.ssh/nameYourKey.pub

将在终端中看到完整的密钥,只能在github中复制和粘贴。

Had the same problem, with the command:
nano ~/.ssh/nameYourKey.pub
because in the terminal dont show some lines of the key.

Solution:
export key with the command cat:

cat ~/.ssh/nameYourKey.pub

will see full key in the terminal, and only do copy and paste in github.

github错误 - 密钥无效。您必须以OpenSSH公共密钥格式提供钥匙

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文