桐祈 2023-01-18 21:44 采纳率: 42.9%
浏览 17
已结题

jypter notebook中的.srot为什么未将list中的”苹果“倒序放在最后输出呢

jypter notebook中的.srot为什么未将list中的”苹果“倒序放在最后输出呢?
相关代码:
# 这是我的购物清单
shoplist = ['apple', 'mango', 'carrot', 'banana']

print('I have', len(shoplist), 'items to purchase.')

print('These items are:', end=' ')
for item in shoplist:
    print(item, end=' ')

print('\nI also have to buy rice.')
shoplist.append('rice')
print('My shopping list is now', shoplist)

print('I will sort my list now')
shoplist.sort()
print('Sorted shopping list is', shoplist)

print('The first item I will buy is', shoplist[0])
olditem = shoplist[0]
del shoplist[0]
print('I bought the', olditem)
print('My shopping list is now', shoplist)

结果:

img

麻烦各位解惑,十分感谢!
  • 写回答

2条回答 默认 最新

  • 专注算法的马里奥学长 人工智能领域新星创作者 2023-01-18 22:17
    关注

    python sort()函数对字符串排序,默认是按照ASCII字符顺序排序,意味着对字母排序的时候,字母越靠后,值越大。所以升序的话apple在前面

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月27日
  • 已采纳回答 1月19日
  • 创建了问题 1月18日

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line