StackOverflow Python 相关问题精选
基础语法
str
list
🔗
🔗
🔗
pythondef foo(a=[]): a.append(5) return a # out >>> foo() [5] >>> foo() [5, 5] >>> foo() [5, 5, 5] >>> foo() [5, 5, 5, 5] >>> foo() # 改写 def foo(a=None): if a is None: a = list() a.append(5) return a🔗
pythonl = [[1, 2, 3], [4, 5, 6], [7], [8, 9]] flat_list = [item for sublist in l for item in sublist] print(flat_list)🔗
🔗
pythontuple(l[i:i+n] for i in xrange(0, len(l), n))🔗
🔗
🔗
🔗
🔗
🔗
🔗
🔗
dict
时间
文件
基本数据结构
🔗
pythonlist_to_be_sorted = [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}] # >>> [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}] newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) # 或者用标准库中的方法: from operator import itemgetter newlist = sorted(list_to_be_sorted, key=itemgetter('name'))🔗
🔗
🔗
🔗
进阶函数和类
系统
数据库
其他
来源
Fork from:
