- 博客(11)
- 收藏
- 关注
原创 使用groupby方法的代码
此段代码是将输入的list triples,每一个列表项都是一个列表每个列表项中,列表index为0的groupby到一起,存储到dict中def getHeadTogether(triples): head_together = {} print('get head together...') triples_ = groupby(sorted(triples), key=lambda x: x[0]) for i, j in triples_: he
2021-10-28 09:58:29 92
原创 python打乱dict
def random_dic(dicts): dict_key_ls = list(dicts.keys()) random.shuffle(dict_key_ls) new_dic = {} for key in dict_key_ls: new_dic[key] = dicts.get(key) return new_dic
2021-10-28 09:55:28 544
原创 python的各个文件读写方法
普通json文件读写def saveJsonFile(location, file): with open(location, 'w') as fw: json.dump(file, fw, ensure_ascii=False, indent=2)def loadData(location): with open(location, 'r') as fr: file = json.load(f) return file大量数据的json按行
2021-10-28 09:53:31 78
转载 调用谷歌翻译的代码
调用谷歌翻译的代码import reimport htmlfrom urllib import parseimport requestsGOOGLE_TRANSLATE_URL = 'http://translate.google.cn/m?q=%s&tl=%s&sl=%s'def translate(text, to_language="auto", text_language="auto"): text = parse.quote(text) url =
2021-10-27 20:43:57 768
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人