dictionary

Mysql数据库密码设置策略

六眼飞鱼酱① 提交于 2020-12-01 10:21:42
场景:在生产环境,我们对密码要求比较高,如密码复杂度、密码有效期、账号授权、账号允许白名单等等 本文档使用:mysql5.7,重点介绍密码复杂度配置 一、修改密码复杂度 1.mysql 5.7.15版本好像默认启用了密码复杂度设置,插件名字叫做 validate_password,如果没有安装 mysql>>INSTALL PLUGIN validate_password SONAME 'validate_password.so'; 2.在/etc/my.cnf加上配置,并重启mysql [mysqld] plugin-load=validate_password.so validate_password_policy=0 validate-password=FORCE_PLUS_PERMANENT 查看默认密码策略 在mysql库下执行一下命令 mysql>use mysql; mysql>set global validate_password_length=8; mysql>set global validate_password_special_char_count=1; mysql>set global validate_password_mixed_case_count=1; mysql>set global validate_password_number_count

Python: Map a function over recursive iterables

随声附和 提交于 2020-12-01 09:23:08
问题 I have an arbitrarily nested iterable like so: numbers = (1, 2, (3, (4, 5)), 7) and I'd like to map a function over it without changing the structure. For example, I might want to convert all the numbers to strings to get strings = recursive_map(str, numbers) assert strings == ('1', '2', ('3', ('4', '5')), '7') Is there a nice way to do this? I can imaging writing my own method to manually traverse numbers , but I'd like to know if there's a general way to map over recursive iterables. Also,

Dictionary value as function to be called when key is accessed, without using “()”

醉酒当歌 提交于 2020-12-01 03:33:27
问题 I have a dictionary that has values sometimes as strings, and sometimes as a functions. For the values that are functions is there a way to execute the function without explicitly typing () when the key is accessed? Example: d = {1: "A", 2: "B", 3: fn_1} d[3]() # To run function I want: d = {1: "A", 2: "B", 3: magic(fn_1)} d[3] # To run function 回答1: Another possible solution, is to create a custom dictionary object that implements this behavior: >>> class CallableDict(dict): ... def _

Dictionary value as function to be called when key is accessed, without using “()”

混江龙づ霸主 提交于 2020-12-01 03:31:42
问题 I have a dictionary that has values sometimes as strings, and sometimes as a functions. For the values that are functions is there a way to execute the function without explicitly typing () when the key is accessed? Example: d = {1: "A", 2: "B", 3: fn_1} d[3]() # To run function I want: d = {1: "A", 2: "B", 3: magic(fn_1)} d[3] # To run function 回答1: Another possible solution, is to create a custom dictionary object that implements this behavior: >>> class CallableDict(dict): ... def _

Dictionary value as function to be called when key is accessed, without using “()”

孤街浪徒 提交于 2020-12-01 03:30:19
问题 I have a dictionary that has values sometimes as strings, and sometimes as a functions. For the values that are functions is there a way to execute the function without explicitly typing () when the key is accessed? Example: d = {1: "A", 2: "B", 3: fn_1} d[3]() # To run function I want: d = {1: "A", 2: "B", 3: magic(fn_1)} d[3] # To run function 回答1: Another possible solution, is to create a custom dictionary object that implements this behavior: >>> class CallableDict(dict): ... def _

Dictionary value as function to be called when key is accessed, without using “()”

▼魔方 西西 提交于 2020-12-01 03:25:19
问题 I have a dictionary that has values sometimes as strings, and sometimes as a functions. For the values that are functions is there a way to execute the function without explicitly typing () when the key is accessed? Example: d = {1: "A", 2: "B", 3: fn_1} d[3]() # To run function I want: d = {1: "A", 2: "B", 3: magic(fn_1)} d[3] # To run function 回答1: Another possible solution, is to create a custom dictionary object that implements this behavior: >>> class CallableDict(dict): ... def _

How can I calculate average of different values in each key of python dictionary?

橙三吉。 提交于 2020-11-29 21:04:37
问题 I have a dictionary. I want to calculate average of values for each key and print result so that the result shows key and associated average. The following code calculates mean but I don't know how to associate key with the average. My desired answer is Mean = {22:average1, 23:average2, 24:average3}. mydict = {22: [1, 0, 0, 1], 23: [0, 1, 2, 1, 0], 24: [3, 3, 2, 1, 0]} Mean =[float(sum(values)) / len(values) for key, values in mydict.iteritems()] 回答1: Don't use a list comprehension. Use a

how to use 'getOwnPropertyNames' to iterate through contents of a map

纵饮孤独 提交于 2020-11-29 10:49:27
问题 I have the map posted below in the code section. I added some values to the map as shown.But when i tried to display the contents of the map using 'getOwnPropertyNames' as shown in th code, the log statement in the loop does not display any thing. please let me know how to utilize 'getOwnPropertyNames' properly code : const mymap = new Map(); const mapKeyToValue = (key, value) => { mymap.set(key, value); }; const getMyMap = () => mymap; mapKeyToValue('1', [{ 'a': 10, 'b': 100, 'c': 1000 }]);

How to convert string representation of dictionary in Pandas DataFrame to a new columns?

╄→尐↘猪︶ㄣ 提交于 2020-11-29 03:28:10
问题 I have a string representation of dictionary in Pandas DataFrame Column like this: >>> df['the_column'] 0 "{'a': 1., 'b': 2., 'c':3.}" 1 "{'a': 4., 'b': 5., 'c':6.}" 2 "{'a': 7., 'b': 8., 'c': 9.}" 3 "{'a': 10., 'b': 11., 'c':12.}" ... I want to append each keys to columns in the existing DataFrame, how is it possible? I have tried something like this: list_of_new_col = [json.loads(c) for c in df['the_column']] # resulting list of dictionary # convert it to pandas DataFrame # and then concat

jieba分词的简单上手教程

喜你入骨 提交于 2020-11-25 11:20:30
简介 jiaba分词是目前最好的Python中文分词组件。支持3种分词模式:精确模式、全模式、搜索引擎模式。 jieba的安装 在Pycharm中, File -> Setting -> Project interpreter -> Add 。搜索 jieba 关键字,点击安装即可。前提是已经配置好了好用的软件源。 三种模式的简单示例 # -*- coding: utf-8 -*- import jieba seg_str = "好好学习,天天向上。" print("/".join(jieba.lcut(seg_str))) # 精简模式,返回一个列表类型的结果 print("/".join(jieba.lcut(seg_str, cut_all=True))) # 全模式,使用 'cut_all=True' 指定 print("/".join(jieba.lcut_for_search(seg_str))) # 搜索引擎模式 分词效果如下: Building prefix dict from the default dictionary ... Loading model from cache C:\Users\j00347382\AppData\Local\Temp\jieba.cache 好好学习/,/天天向上/。 好好/好好学/好好学习/好学/学习/,/天天/天天向上/向上