python是什么 python中如何計算列表中元素的個數(shù)?
python中如何計算列表中元素的個數(shù)?描述len() 方法返回列表元素個數(shù)。語法len()方法語法:len(list)參數(shù)list -- 要計算元素個數(shù)的列表。返回值返回列表元素個數(shù)。實例以下實例展
python中如何計算列表中元素的個數(shù)?
描述len() 方法返回列表元素個數(shù)。語法len()方法語法:len(list)參數(shù)list -- 要計算元素個數(shù)的列表。返回值返回列表元素個數(shù)。實例以下實例展示了 len()函數(shù)的使用方法:#!/usr/bin/pythonlist1, list2 = [123, "xyz", "zara"], [456, "abc"]print "First list length : ", len(list1)print "Second list length : ", len(list2)以上實例輸出結(jié)果如下:First list length : 3Second lsit length : 2
python text中按字典序排列最小的子序列?
class Solution(object):
def smallestSubsequence(self, text):
"""
:type text: str
:rtype: str
"""
stack = []
last_o = {}
considered = {}
for i in range(len(text)-1,-1,-1):
if text[i] not in last_o:
last_o[text[i]] = i
considered[text[i]] = False
print(last_o)
i = 0
while i < len(text):
print(stack,i,text[i])
if len(stack) == 0:
stack.append(text[i])
considered[text[i]] = True
i =1
elif stack[-1]>text[i] and considered[text[i]] == False:
if last_o[stack[-1]]>i:
considered[stack[-1]]=False
stack.pop()
else:
considered[text[i]] = True
stack.append(text[i])
i =1
elif stack[-1]<text[i] and considered[text[i]] == False:
stack.append(text[i])
considered[text[i]] = True
i =1
else:
i =1
return "".join(i for i in stack)