![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Katherine_pbq
这个作者很懒,什么都没留下…
展开
-
python_dict_嵌套value值处理
1.使用嵌套的字典allGuests = {‘Alice’: {‘apples’: 5, ‘pretzels’: 12},‘Bob’: {‘ham sandwiches’: 3, ‘apples’: 2},‘Carol’: {‘cups’: 3, ‘apple pies’: 1}} def getnum(guest,item): num = 0 for k,v in allGue...原创 2019-01-14 11:42:14 · 518 阅读 · 0 评论 -
python_dict_好玩游戏的物品清单
Inventory列出清单并计算总和stuff = {'rope':1,'torch':6,'gold coin':42,'dagger':1,'arrow':12}def displayInventory(stuff): print('Inventory:') value_total = 0 for k,v in stuff.items(): pr...原创 2019-01-14 13:39:51 · 238 阅读 · 0 评论 -
python_读写文件_open
IO 文件读写读:f = open('/Users/panbingqing/Desktop/test/a.rtf') #读模式,不可做任何修改#将整个文件内容读取为一个字符串值,使用read()方法f1 = f.read()#or use readlines()将整个文件读取为列表f2 = f.readlines()type(f2) #strtype(f1) #list写:IO...原创 2019-01-14 15:05:59 · 192 阅读 · 0 评论 -
python小知识
列表:反向排序list_test = [1,2,3,4,5]list_test = list_test[::-1]print('列表反向顺序为:'+str(list_test))开头插入元素list_test[:0] = [7,6]join连接到字符串list_test = ['2018','10','29']'-'.join(list_test)列表推倒式list_t...原创 2019-01-15 14:38:03 · 220 阅读 · 0 评论 -
Codewars-python 20190117
1.Descending Ordersinput:324189output:984321知识点:’’.join[::-1]:list倒序排列def Descending_Order(num): #Bust a move right here num = list(str(num)) return int(''.join(sorted(num)[::-1]))2...原创 2019-01-16 16:33:42 · 220 阅读 · 0 评论