gpt4 book ai didi

python - 检查元组中的顺序

转载 作者:太空宇宙 更新时间:2023-11-04 01:16:05 27 4
gpt4 key购买 nike

我得到了一堆从 0 到 9 的 5 个数字的元组。我想检查元组是按升序还是降序排序(即 12345 02455 97311)。怎么会这样?

最佳答案

试试这个

if some_tuple == tuple(sorted(some_tuple, reverse=True)):
# Order is Descending
elif some_tuple == tuple(sorted(some_tuple)):
# Order is Ascending
else:
# No order

关于python - 检查元组中的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24591448/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com