Python names in a list -
so i'm kinda new python , given problem follows: given list names , find largest element in list , swap last element. example, list ["carlton", "quincy" "adam", "bernard"] become ["carlton", "bernard", "adam", "quincy"] . assume names not empty
i thought doing list comprehension don't know how write out in code
edit: largest in case length of string (sorry not clarifying!!!))
names = [foo, fooooo, bar, baaar] a, b = i.index(max(name, key=len)), -1 i[b], i[a] = i[a], i[b]
courtesy of this.
Comments
Post a Comment