# encoding = utf-8
# 开发者:xxx
# 开发时间: 11:38
# "Stay hungry,stay foolish."
class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
if target in nums:
return nums.index(target)
else:
nums.append(target)
nums.sort()
return nums.index(target)
if __name__ == '__main__':
sol = Solution()
print(sol.searchInsert([1, 3, 5, 6], 2))
所用方法:
找列表中的元素位置
#列表
listA = ["o", "u" , "i"]
#获取u的索引并打印
index_u = listA.index("u")
print(index_u)