表达式sorted111233key=lambda xlenstrx的值为____写过过程
结果为:[2, 33, 111]
解析: sorted([111,2,33],key=lambda x:len(str(x)))的意思是按照每个元素转换为字符串后的长度来进行排序。lambda x:len(str(x))表示将x转换为字符串后求得字符串长度,即将[111,2,33]转换为['111', '2', '33'],按照字符串长度进行排序,结果为['2', '33', '111']。
原文地址: https://www.cveoy.top/t/topic/hfO5 著作权归作者所有。请勿转载和采集!