Daiyue Weng wrote:
> Hi, I have a list numbers say,
> First, I want to calculate the sum of the differences between the numbers
> in the list.
> Second, if a sequence of numbers having a difference of 1, put them in a
> list, i.e. there are two such lists,
Why isn't 4 in that list?
> and also put the rest numbers in another list, i.e. there is only one such
> list in the example,
> Third, get the lists with the max/min sizes from above, i.e. in this
> example, the max list is,
> min list is
In addition to Steve's hint: max() takes a key argument, e. g. to get the
string with the highest amount of "a"s:
>>> max(["xyz", "abc", "alpha"], key=lambda s: s.count("a"))
Finding the longest string or list doesn't even require you to define your