项目作者: ihgazni2

项目描述 :
A list of dict , each dict has only one key.
高级语言: Python
项目地址: git://github.com/ihgazni2/dlist.git
创建时间: 2018-11-22T02:38:03Z
项目社区:https://github.com/ihgazni2/dlist

开源协议:MIT License

下载


dlist

A list of dict.

Each dict-element has only one key.

Such as: [ {k1:v1},{k2:v2},{k3,v3}]

Documents

https://ihgazni2.github.io/dlist/

Functions

is_dlist(obj)

  1. from dlist import *
  2. rslts[0] = (is_dlist([]) == True)
  3. rslts[1] = (is_dlist([{1:'a'},{2:'b'}]) == True)
  4. rslts[2] = (is_dlist([{1:'a',2:'b'},{3:'c',4:'d'}]) == False)

dict2dlist(this_dict,**kwargs)

  1. from dlist import *
  2. d = {1:2,3:4,5:6,7:8}
  3. rslts[3] = (dict2dlist(d) == [{1: 2}, {3: 4}, {5: 6}, {7: 8}])

dlist2dict(dict_list,**kwargs)

  1. from dlist import *
  2. d = {1:2,3:4,5:6,7:8}
  3. dl = [{1: 2}, {3: 4}, {5: 6}, {7: 8}]
  4. rslts[4] = (dlist2dict(dl) == d)

kvlist2dlist(klist,vlist,**kwargs)

dlist2kvlist(dict_list,**kwargs)

  1. from dlist import *
  2. d = {1:2,3:4,5:6,7:8}
  3. dl = [{1: 2}, {3: 4}, {5: 6}, {7: 8}]
  4. kl = [1,3,5,7]
  5. vl = [2,4,6,8]
  6. rslts[5] = (dlist2kvlist(dl) == (kl,vl))
  7. rslts[6] = (kvlist2dlist(kl,vl) == dl)

extend(dict_list_1,dict_list_2,**kwargs)

  1. from dlist import *
  2. dl1 = [{1:2},{3:4}]
  3. dl2 = [{5:6},{7:8}]
  4. extend(dl1,dl2)
  5. rslts[7] = (dl1 == [{1: 2}, {3: 4}, {5: 6}, {7: 8}])

prextend(dict_list_1,dict_list_2,**kwargs)

  1. dl1 = [{1:2},{3:4}]
  2. dl2 = [{5:6},{7:8}]
  3. prextend(dl1,dl2)
  4. rslts[8] = (dl1 == [{5: 6}, {7: 8},{1: 2}, {3: 4}])

concat(dict_list_1,dict_list_2,**kwargs)

  1. dl1 = [{1:2},{3:4}]
  2. dl2 = [{5:6},{7:8}]
  3. dl = concat(dl1,dl2)
  4. rslts[9] = (dl == [{1: 2}, {3: 4}, {5: 6}, {7: 8}])

first_islice(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[10] = (first_islice(dl,key='a') == [1, 2])
  4. rslts[11] = (first_islice(dl,mode='value',value='b') == [3, 4])
  5. rslts[12] = (first_islice(dl,mode='kv',key='c',value='c') == [5, 6])

last_islice(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[13] = (last_islice(dl,key='a') == [7, 8])
  4. rslts[14] = (last_islice(dl,mode='value',value='b') == [9, 10])
  5. rslts[15] = (last_islice(dl,mode='kv',key='c',value='c') == [11, 12])

all_islice(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[16] = (all_islice(dl,key='a') == [[1, 2], [7, 8]])
  4. rslts[17] = (all_islice(dl,mode='value',value='b') == [[3, 4], [9, 10]])
  5. rslts[18] = (all_islice(dl,mode='kv',key='c',value='c') == [[5, 6], [11, 12]])

indexes(dict_list,value,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[19] = (indexes(dl,key='a') == [1, 2, 7, 8]])
  4. rslts[20] = (indexes(dl,mode='value',value='b') == [3, 4, 9, 10])
  5. rslts[21] = (indexes(dl,mode='kv',key='a',value='y') == [2,8])

first_index(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[22] = (first_index(dl,key='a') == 1)
  4. rslts[23] = (first_index(dl,mode='value',value='b') == 3)
  5. rslts[24] = (first_index(dl,mode='kv',key='a',value='y') == 2)

last_index(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[25] = (last_index(dl,key='a') == 8)
  4. rslts[26] = (last_index(dl,mode='value',value='b') == 10)
  5. rslts[27] = (last_index(dl,mode='kv',key='a',value='y') == 8)

append(dict_list,key,value,**kwargs)

prepend(dict_list,key,value,**kwargs)

  1. from dlist import *
  2. dl = [{1:'a'},{2:'b'},{3:'c'}]
  3. rslts[28] = (append(dl,'k','v') == [{1: 'a'}, {2: 'b'}, {3: 'c'}, {'k': 'v'}])
  4. dl = [{1:'a'},{2:'b'},{3:'c'}]
  5. rslts[29] = (prepend(dl,'k','v') == [{'k': 'v'}, {1: 'a'}, {2: 'b'}, {3: 'c'}])

clear(dict_list,**kwargs)

insert(dict_list,index,key,value,**kwargs)

insert_dlist(dict_list_1,index,dict_list_2,**kwargs)

  1. from dlist import *
  2. dl = [{1:'a'},{2:'b'},{3:'c'}]
  3. rslts[30] = (insert(dl,1,'k','v') == [{1: 'a'}, {'k': 'v'},{2: 'b'}, {3: 'c'}])
  4. dl = [{1:'a'},{2:'b'},{3:'c'}]
  5. dl2 = [{'k1':'v1'},{'k2':'v2'}]
  6. rslts[31] = (insert_dlist(dl,1,dl2) == [{1: 'a'}, {'k1':'v1'},{'k2':'v2'},{'k': 'v'},{2: 'b'}, {3: 'c'}])

include(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[32] = (include(dl,key='b') == False)
  4. rslts[33] = (include(dl,mode='value',value='b') == True)
  5. rslts[34] = (include(dl,mode='kv',key='a',value='y') == True)

count(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[35] = (count(dl,key='a') == 4)
  4. rslts[36] = (count(dl,mode='value',value='b') == 4)
  5. rslts[37] = (count(dl,mode='kv',key='a',value='y') == 2)

pop(dict_list,**kwargs)

pop_range(dict_list,start,end,**kwargs)

pop_seqs(dict_list,seqs_set,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. pop(dl,index=1)
  4. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  5. rslts[38] = (pop(dl,mode='key',key='a') == [{'a': 'x'}, {'a': 'y'}, {'a': 'x'}, {'a': 'y'}])
  6. rslts[39] = (dl == [{1: 2}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}] )
  7. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  8. rslts[40] = (pop_range(dl,1,4) == [{'a': 'x'}, {'a': 'y'}, {3: 'b'}])
  9. rslts[41] = (dl == [{1: 2}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])
  10. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  11. rslts[42] = (pop_seqs(dl,[0,2,4]) == [{1: 2}, {'a': 'y'}, {5: 'b'}])
  12. rslts[43] = (dl = [{'a': 'x'}, {3: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])

rm_first(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[44] = (rm_first(dl,key='a') == [{1: 2}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])
  4. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  5. rslts[45] = (rm_first(dl,mode='value',value='b') == [{1: 2}, {'a': 'x'}, {'a': 'y'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])
  6. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  7. rslts[46] = (rm_first(dl,mode='kv',key='a',value='y') == [{1: 2}, {'a': 'x'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])

rm_last(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[47] = (rm_last(dl,key='a') == [{1: 2}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])
  4. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  5. rslts[48] = (rm_last(dl,mode='value',value='b') == [{1: 2}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {'c': 'c'}, {'c': 'c'}])
  6. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  7. rslts[49] = (rm_last(dl,mode='kv',key='a',value='y') == [{1: 2}, {'a': 'x'}, {'a': 'y'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])

rm_all(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[47] = (rm_all(dl,key='a') == [{1: 2}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])
  4. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  5. rslts[48] = (rm_all(dl,mode='value',value='b') == [{1: 2}, {'a': 'x'}, {'a': 'y'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'y'}, {'c': 'c'}, {'c': 'c'}])
  6. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  7. rslts[49] = (rm_all(dl,mode='kv',key='a',value='y') == [{1: 2}, {'a': 'x'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}])

reverse(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[53] =(reverse(dl) == [{'c': 'c'}, {'c': 'c'}, {5: 'b'}, {3: 'b'}, {'a': 'y'}, {'a': 'x'}, {'c': 'c'}, {'c': 'c'}, {5: 'b'}, {3: 'b'}, {'a': 'y'}, {'a': 'x'}, {1: 2}])

sort(dict_list,**kwargs)

  1. from dlist import *
  2. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  3. rslts[54] = (sort(dl) == [{1: 2}, {3: 'b'}, {3: 'b'}, {5: 'b'}, {5: 'b'}, {'a': 'x'}, {'a': 'x'}, {'a': 'y'}, {'a': 'y'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}])
  4. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  5. rslts[55] = (sort(dl,mode='vk') == [{1: 2}, {3: 'b'}, {3: 'b'}, {5: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'x'}, {'a': 'y'}, {'a': 'y'}])
  6. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  7. rslts[56] = (sort(dl,mode='key') == [{1: 2}, {3: 'b'}, {3: 'b'}, {5: 'b'}, {5: 'b'}, {'a': 'x'}, {'a': 'y'}, {'a': 'x'}, {'a': 'y'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}])
  8. dl = [{1:2},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'},{'a':'x'},{'a':'y'},{3:'b'},{5:'b'},{'c':'c'},{'c':'c'}]
  9. rslts[57] = (sort(dl,mode='value') == [{1: 2}, {3: 'b'}, {5: 'b'}, {3: 'b'}, {5: 'b'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'c': 'c'}, {'a': 'x'}, {'a': 'x'}, {'a': 'y'}, {'a': 'y'}])

comprise(dict_list1,dict_list2,**kwargs)

  1. from dlist import *
  2. dl1 = [{1:2},{3:4},{5:6},{7:8}]
  3. dl2 = [{3:4},{5:6}]
  4. rslts[58] = (comprise(dl1,dl2) == True)
  5. rslts[59] = (comprise(dl1,dl2,strict=True) == False)

tuple2dict(t)

dict2tuple(d)

  1. from dlist import *
  2. d = {1:2}
  3. rslts[62] = (dict2tuple(d) == (1, 2))
  4. t = (1, 2)
  5. rslts[63] = (tuple2dict(t) == {1:2})

dlist2tlist(dl)

tlist2dlist(tl)

  1. from dlist import *
  2. dl = [{1:2},{3:4},{5:6},{7:8}]
  3. rslts[60] = (dlist2tlist(dl) == [(1, 2), (3, 4), (5, 6), (7, 8)])
  4. tl = [(1, 2), (3, 4), (5, 6), (7, 8)]
  5. rslts[61] = (tlist2dlist(tl) == [{1:2},{3:4},{5:6},{7:8}])

cmp_dele(d1,d2,**kwargs)

  1. from dlist import *
  2. d1 = {1:2}
  3. d2 = {2:1}
  4. rslts[64] = (cmp_dele(d1,d2,mode='key') == -1)
  5. rslts[65] = (cmp_dele(d1,d2,mode='value') == 1)
  6. d3 = {3:4}
  7. d4 = {3:5}
  8. rslts[66] = (cmp_dele(d3,d4,mode='kv') == -1)
  9. d5 = {7:6}
  10. d6 = {8:6}
  11. rslts[67] = (cmp_dele(d5,d6,mode='vk') == 1)
  12. rslts[68] = (cmp_dele(d5,d5) == 0)