摘要: import itertools original_list = [[2,4,3],[1,5,6], [9], [7,9,0]] new_merged_list = list(itertools.chain(*original_list)) print(new_merged_list) 阅读全文
posted @ 2018-11-22 21:29 anobscureretreat 阅读(2716) 评论(0) 推荐(0)
摘要: 输出 阅读全文
posted @ 2018-11-22 20:32 anobscureretreat 阅读(216) 评论(0) 推荐(0)
摘要: import re x=re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') print(x) 阅读全文
posted @ 2018-11-22 20:29 anobscureretreat 阅读(1410) 评论(0) 推荐(0)
摘要: def scope_test(): def do_local(): spam = "local spam" def do_nonlocal(): nonlocal spam spam = "nonlocal spam" def do_global(): global spam spam... 阅读全文
posted @ 2018-11-22 20:27 anobscureretreat 阅读(208) 评论(0) 推荐(0)
摘要: 输出 阅读全文
posted @ 2018-11-22 19:49 anobscureretreat 阅读(458) 评论(0) 推荐(0)
摘要: import os with os.scandir(r"C:\Users\macname\Desktop") as it: for entry in it: if entry.name.startswith('Auto') and entry.is_file(): print(entry.name) 阅读全文
posted @ 2018-11-22 19:43 anobscureretreat 阅读(385) 评论(0) 推荐(0)
摘要: import os with os.scandir(r"C:\Users\macname\Desktop") as it: for entry in it: if not entry.name.startswith('Auto') and entry.is_file(): print(entry.name) 阅读全文
posted @ 2018-11-22 19:39 anobscureretreat 阅读(304) 评论(0) 推荐(0)
摘要: 打印所有以.txt为结尾的文件名称 阅读全文
posted @ 2018-11-22 17:41 anobscureretreat 阅读(413) 评论(0) 推荐(0)
摘要: 输出 阅读全文
posted @ 2018-11-22 17:27 anobscureretreat 阅读(199) 评论(0) 推荐(0)
摘要: 同:都是能遍历集合(表、数组) 异:ipairs 仅仅遍历值,按照索引升序遍历,索引中断停止遍历。即不能返回 nil,只能返回数字 0,如果遇到 nil 则退出。它只能遍历到集合中出现的第一个不是整数的 key。 pairs 能遍历集合的所有元素。即 pairs 可以遍历集合中所有的 key,并且除 阅读全文
posted @ 2018-11-22 12:38 anobscureretreat 阅读(328) 评论(0) 推荐(0)
摘要: local tab= { [1] = "a", [3] = "b", [4] = "c" } for i,v in pairs(tab) do -- 输出 "a" ,"b", "c" , print( tab[i] ) end for i,v in ipairs(tab) do -- 输出 "a" ,k=2时断开 print( tab[... 阅读全文
posted @ 2018-11-22 11:48 anobscureretreat 阅读(202) 评论(0) 推荐(0)
摘要: 泛型 for 迭代器 输出 无状态的迭代器 输出 多状态的迭代器 输出 阅读全文
posted @ 2018-11-22 11:47 anobscureretreat 阅读(220) 评论(0) 推荐(0)
摘要: 输出 阅读全文
posted @ 2018-11-22 11:13 anobscureretreat 阅读(166) 评论(0) 推荐(0)
摘要: function trim(s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end string1 = " RUNOOB " string2 = trim(string1) print(string2) 阅读全文
posted @ 2018-11-22 11:13 anobscureretreat 阅读(431) 评论(0) 推荐(0)
摘要: local function NumToCN(num) local size = #tostring(num) local CN = "" local StrCN = {"一","二","三","四","五","六","七","八","九"} for i = 1 , size do CN = CN .. StrCN[tonumber(strin... 阅读全文
posted @ 2018-11-22 11:12 anobscureretreat 阅读(1091) 评论(0) 推荐(0)
摘要: 字符串或串(String)是由数字、字母、下划线组成的一串字符。 Lua 语言中字符串可以使用以下三种方式来表示: 单引号间的一串字符。 双引号间的一串字符。 [[和]]间的一串字符。 示例 输出 string.upper(argument):字符串全部转为大写字母 string.lower(arg 阅读全文
posted @ 2018-11-22 10:19 anobscureretreat 阅读(309) 评论(0) 推荐(0)
摘要: import json,time # save data to json file def store(data): with open('data.json', 'w') as fw: # 将字典转化为字符串 # json_str = json.dumps(data) # fw.write(json_str) # 上面... 阅读全文
posted @ 2018-11-22 00:34 anobscureretreat 阅读(236) 评论(0) 推荐(0)
摘要: 提示说是解码错误 可以用下面的方法判断json文件是否为空 但是在非空情况下会报错!!! 已解决!!!https://www.cnblogs.com/sea-stream/p/10011699.html 阅读全文
posted @ 2018-11-22 00:25 anobscureretreat 阅读(1916) 评论(0) 推荐(0)