小编Jan*_*s02的帖子

在 Python 中根据元组的乘积对列表中的元组进行排序

我正在尝试编写一个过程来根据每个元组的乘积值对列表中的元组进行排序。我只是尝试先使用 while 循环对它们进行排序,但我无法整合元组内数字的乘法。到目前为止我的代码是:

def sort_list (a):
    i = 0
    while i < len(a):
        key = i
        j = i + 1
        
        #first checking throuh the whole list if any number is bigger
        
        while j < len(a):
            if a[key] > a [j]:
                key = j
            j += 1
            
        #swap the numbers if the key one (i) is bigger than the j one the j one will be the new key
        # and swapped in the next section!
        
        a[i], a[key] = a[key], …
Run Code Online (Sandbox Code Playgroud)

python sorting product tuples

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

标签 统计

product ×1

python ×1

sorting ×1

tuples ×1