是否有可能为github做自动提交。(Is it possible to do auto-commit for github.)
我希望能够自动将我的工作提交给github每个让我们说... 8小时。
是否可以为我的笔记本电脑设置它。 我有Windows机器。
任何人都可以在正确的方向引导我如何做到这一点?
I want to be able to auto commit my work to github every lets say.. 8 hours.
Is it possible to set it up for my laptop. i have windows machine.
Can anyone guide me in the right direction on how I can do this?
原文:https://stackoverflow.com/questions/29653584
最满意答案
你可以使用嵌套的字典,嵌套的defaultdicts或Trie 。
使用标准的字典,你可以使用
setdefault
:tree = {} tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, []).append(prop)
它会给你一个列表字典的字典。 如果你想在树叶上设置,你可以使用:
tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, set()).add(prop)
举个例子:
data = [ ('cmd1', 'typeA', 3, 'propertyX'), ('cmd1', 'typeA', 3, 'propertyZ'), ('cmd1', 'typeB', 2, 'propertyY'), ('cmd2', 'typeA', 3, 'propertyX'), ('cmd2', 'typeB', 1, 'propertyZ'), ('cmd2', 'typeA', 1, 'propertyX'), ('cmd1', 'typeB', 2, 'propertyZ') ] tree = {} for cmd, cmd_type, dimension, prop in data: tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, []).append(prop) from pprint import pprint pprint(tree)
它输出:
{'cmd1': {'typeA': {3: ['propertyX', 'propertyZ']}, 'typeB': {2: ['propertyY', 'propertyZ']}}, 'cmd2': {'typeA': {1: ['propertyX'], 3: ['propertyX']}, 'typeB': {1: ['propertyZ']}}}
使用defaultdicts,您的代码将如下所示:
tree = defaultdict(lambda: defaultdict(lambda: defaultdict(list))) for cmd, cmd_type, dimension, prop in data: tree[cmd][cmd_type][dimension].append(prop)
You could use nested dicts, nested defaultdicts or a Trie.
With standard dicts, you'd use
setdefault
:tree = {} tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, []).append(prop)
It would give you a dict of dicts of dicts of lists. If you want sets at the leaves, you could use:
tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, set()).add(prop)
As an example:
data = [ ('cmd1', 'typeA', 3, 'propertyX'), ('cmd1', 'typeA', 3, 'propertyZ'), ('cmd1', 'typeB', 2, 'propertyY'), ('cmd2', 'typeA', 3, 'propertyX'), ('cmd2', 'typeB', 1, 'propertyZ'), ('cmd2', 'typeA', 1, 'propertyX'), ('cmd1', 'typeB', 2, 'propertyZ') ] tree = {} for cmd, cmd_type, dimension, prop in data: tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, []).append(prop) from pprint import pprint pprint(tree)
It outputs:
{'cmd1': {'typeA': {3: ['propertyX', 'propertyZ']}, 'typeB': {2: ['propertyY', 'propertyZ']}}, 'cmd2': {'typeA': {1: ['propertyX'], 3: ['propertyX']}, 'typeB': {1: ['propertyZ']}}}
With defaultdicts, your code would look like:
tree = defaultdict(lambda: defaultdict(lambda: defaultdict(list))) for cmd, cmd_type, dimension, prop in data: tree[cmd][cmd_type][dimension].append(prop)
相关问答
更多-
如果我可以改写你的问题,你想要的是一个字典,其中有几年的键和每年的数组,包含与该年相关联的值列表,对吧? 这是我如何做到的: years_dict = dict() for line in list: if line[0] in years_dict: # append the new number to the existing array at this slot years_dict[line[0]].append(line[1]) else: ...
-
您可以运行以下内容,例如: max_value = max(scores.values()) keys = [ i for (i,v) in scores.iteritems() if v == max_value ] “键”现在将保存与最大值对应的所有键。 You could run the following, for example: max_value = max(scores.values()) keys = [ i for (i,v) in scores.iteritems() if v == ...
-
在exec_command执行之后,只有paramiko关闭了通道,并且ssh返回一个auth提示符。 似乎它不可能与paramiko ,尝试fabric或其他工具。 ** fabric也没有解决 。 With just paramiko after the exec_command executes the channel is closed and the ssh returns an auth prompt. Seems its not possible with just paramiko, try ...
-
要将cur.execute作为列表cur.execute中的附加操作调用,您可以使用一些虚拟var和列表( cur.execute放在list [ ]中创建可迭代的一个元素,只调用包含的函数),不会在结果dict中使用。 并且您的j var不需要并且替换为调用extract_dbs_tbls : {i: extract_dbs_tbls(cur, s = 'show tables') for i in lst for dummy in [cur.execute('use %i' % i)]} 以上等同 ...
-
dict.update()函数可以采用可重复的(key, value)对; 你在那里的代码传递一个生成这样的对的生成器表达式 。 它遍历sub.BACKENDS.items()并且每对只选择那些val.enabled()方法返回True 。 你也可以把它表达为for循环: for key, value in sub.BACKENDS.items(): if value.enabled(): backends[key] = value dict.get()函数返回键或默认值。 这里默 ...
-
popdict = {} incdict = {} for ix, city in enumerate(WyomingCnty): popdict[city] = dict(zip(Years, popdata.col_values(colx=ix + 1,start_rowx=1,end_rowx=None) incdict[city] = dict(zip(Years, incomedata.col_values(colx=ix + 1,start_rowx=1,end_rowx=None) ...
-
为什么关键字搜索比通过python字典进行迭代更快[复制](Why is key search faster than iteration through python dictionary [duplicate])[2022-08-15]
因为Python中的字典是使用散列表实现的。 想象一下类似于关系数据库中的索引,这使得关键的查找操作更快。 参考 Because dictionaries in python are implemented using hash tables. Think something similar to indices in a relational database, which make key seeking operations faster. Reference -
你可以使用嵌套的字典,嵌套的defaultdicts或Trie 。 使用标准的字典,你可以使用setdefault : tree = {} tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(dimension, []).append(prop) 它会给你一个列表字典的字典。 如果你想在树叶上设置,你可以使用: tree.setdefault(cmd, {}).setdefault(cmd_type, {}).setdefault(di ...
-
在字典中,如何从具有多个值的键中删除值?(within a dictionary, how do I remove a value from a key with multiple values? Python)[2022-01-04]
dict理解。 return {x : [i for i in dictionary[x] if not i.lower().endswith('ing')] for x in dictionary} 编辑用'替换'替换以'ing'结尾的值 return {x : [i if not i.lower().endswith('ing') else 'removed' for i in dictionary[x]] for x in dictionary} dict comprehension. retur ... -
您可以使用字典理解来删除每个元组中的第一个项目: dictionary = {k: v for (_, k), v in dictionary.items()} You can use a dictionary comprehension dropping the first item in each tuple: dictionary = {k: v for (_, k), v in dictionary.items()}