小编use*_*653的帖子

在包含数字和字符串的列表上使用max()

我有一个这样的列表:

self.thislist = ['Name', 13, 'Name1', 160, 'Name2', 394]
Run Code Online (Sandbox Code Playgroud)

基本上,列表后面有一个名称和一个数字,我试图找出列表中的最高数字,即394.但出于某种原因,它选择了一个名字this.

      if max(self.thislist) > 150:
            this = max(self.thislist) # so this should be 394
            position = self.thislist.index(this) # The index of it
            temponary = position - 1 # This is so we can find the name that is associated with it
            name = self.thislist[temponary] #and this retrieves the name
Run Code Online (Sandbox Code Playgroud)

例如,'Name'当它应该是394时,它会检索.因此,重点是检索与该名称相关联的名称和数字.有任何想法吗?

python string int list max

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

标签 统计

int ×1

list ×1

max ×1

python ×1

string ×1