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

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -