python - Find first item with alphabetical precedence in list with numbers -


say have list object occupied both numbers , strings. if want retrieve first string item highest alphabetical precedence, how so?

here example attempt incorrect, corrections needs changed in order achieve desired result appreciated:

lst = [12, 4, 2, 15, 3, 'alligator', 'bear', 'anteater', 'dog', 'cat']  lst.sort() in lst:    if i[0] == "a":       answer = print(answer) 

first use generator expression filter out non-strings, , use min() select string highest alphabetical presence:

>>> min(x x in lst if isinstance(x, str)) 'alligator 

Comments

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -