小编Joe*_*man的帖子

将两个已排序的列表合并为一个更大的排序列表

我正在尝试创建一个合并函数,将在我正在进行的合并排序中使用.

我遇到了一些麻烦,我似乎无法找到错误.

我评论它试图向你们展示我的思考过程:

def merge(aList, bList):
    newList = []
    while (len(aList) > 0) & (len(bList) > 0):  #Loop until both lists are empty
        if aList[0] < bList[0]:         #If the first item of aList is smaller than the first item of bList
            newList.append(aList[0])    #add that item to the new list
            aList.pop(0)                #and remove it from the original list

        else:                           #If it gets here, that means the first item of bList was smaller
            newList.append(bList[0])    #So put the first item of bList is …
Run Code Online (Sandbox Code Playgroud)

python sorting

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

Kotlin:如何修改一对中的值?

为什么我不能更改对中的值:

var p: Pair<Int, String> = Pair(5, "Test")
p.first = 3
Run Code Online (Sandbox Code Playgroud)

错误p.first:Val无法重新分配

tuples kotlin

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

在IF子句中OR'ing多个值选项的替代方法是什么?

是否有任何c#语法可以使if语句更清晰/更短?

if (token == "(" || token == ")" || token == "+" || token == "-" || token == "*" || token == "/")
{
     //do something
}
Run Code Online (Sandbox Code Playgroud)

c# if-statement

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

在c#中检查用户输入是否为整数

所以我正在制作一个小文本游戏,当它要求网格大小时,我需要用户输入一个整数。如果没有输入整数,我希望再次提出这个问题。

现在我有:

Console.WriteLine("Enter Grid Size.");
int gridSize = int.Parse(Console.ReadLine());
Run Code Online (Sandbox Code Playgroud)

我需要一种方法来检查输入是否为整数,然后再次询问是否为整数。谢谢

c#

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

标签 统计

c# ×2

if-statement ×1

kotlin ×1

python ×1

sorting ×1

tuples ×1