小编Tyl*_*eed的帖子

创建一个对两个列表进行排序的函数

我正在尝试创建一个函数,该函数返回已排序的字符串列表,但带有附加条件,该函数将对所有以w / 'x'first 开头的字符串进行排序。

因此,例如,列表['mix', 'xyz, 'apple', 'xanadu'] 将产生['xanadu', xyz', 'apple', 'mix']

def front_x(words):
    x = []
    y = []
    for k, v in enumerate(words):
        if v.startswith("x"):
            x.append(v)
        else:
            y.append(v)

    x.sort()
    y.sort()
    print(x.extend(y))

this_list = ['mix', 'xyz', 'apple', 'xanadu', 'aardvark']

front_x(this_list)
Run Code Online (Sandbox Code Playgroud)

这给了我输出None。

python sorting list

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

标签 统计

list ×1

python ×1

sorting ×1