Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

ihgazni2/elist

Repository files navigation

elist

handle list ,nested list tree

install

pip3 install elist

class ListTree

1. __init__(alist)

    from elist.elist import *
    from xdict.jprint import pobj
    from xdict.jprint import pdir
    l = [1, [4], 2, [3, [5, 6]]]
    ltree = ListTree(l)

2. __repr__

    l
    ltree
    pobj(ltree.showlog)

3. tree(**kwargs)

    pathlists = ltree.tree()
    pathlists = ltree.tree(leaf_only=True)
    pathlists = ltree.tree(leaf_only=True,from_lv=1,to_lv=2)
    pathlists = ltree.tree(non_leaf_only=True)

4. flatten()

    flat = ltree.flatten()
    flat
    ltree.flatWidth
    ltree.depth

5. dig(howmanysteps)

    depthfirst = ltree.dig()
    depthfirst = ltree.dig(2)
    depthfirst = ltree.dig(5)

6. level(whichlevel,**kwargs)

    level = ltree.level(1)
    level = ltree.level(1,leaf_only=True)
    level = ltree.level(1,non_leaf_only=True)
    level = ltree.level(2)
    level = ltree.level(3)

7. include(*pathlist,**kwargs)

    l[3][1][0]
    ltree.include(3,1,0)
    l[3][1][2]
    ltree.include(pathlist = [3,1,2])

8. __getitem__(*pathlist)

    ltree[1,0]
    l[1][0]
    ltree[3,1,1]
    l[3][1][1]

9A. search(value,**kwargs)

    from xdict.TestLib.genrand import gen_random_recursive_only_list_data as randlist
    # lets generate a l for test,l is a big nested-list
    l = randlist()
    #the l looks like the below:

    #you can see the value "v_4" appears in different levels of the nested-list:

    ltree = ListTree(l)
    pathlists = ltree.search('v_4')
    pathlists.__len__()
    #we will found 125 match

    #......

    l[0]
    l[4][2][1][0][0][3]
    l[4][2][1][0][0][19][11]
    l[11][3]

9B. cond_search(value,**kwargs)

    pl1=ltree.search('v_4')
    pl1.__len__() 
    #we found 125 match of "v_4"
    pl2=ltree.search('v_8')
    pl2.__len__()
    #we found 117 match of "v_8"

    #the next we need to found "v_4" or "v_8" whose pathlist includes <14>, and the <14> appears at index <4> in the pathlist
    def cond_func(ele_value,ele_pathlist,position):
        cond1 = ("4" in ele_value) | ("8" in ele_value)
        cond2 = (14 in ele_pathlist)
        cond3 = False
        if(cond2):
            cond3 = (ele_pathlist.index(14) == position)
        else:
            pass
        return(cond1 & cond2 & cond3)

    position = 4
    pl = ltree.cond_search(cond_func=cond_func,cond_func_args=[position])

    #verify the values

ListTree lquery APIs:


├──10. ancestor_paths
├──11. ancestors
├──12. parent_path
├──13. parent
├──14. descendant_paths
├──15. descendants
├──16. prevSibPath
├──17. prevSibling
├──18. nextSibPath
├──19. nextSibling
├──20. lsib_path
├──21. lsib
├──22. rsib_path
├──23. rsib
├──24. sib_paths
├──25. sibs
├──26. someSibPaths
├──27. someSibs
├──28. some_sib_paths
├──29. some_sibs
├──30. whichSibPath
├──31. whichSib
├──32. which_sib_path
├──33. which_sib
├──34. precedingSibPaths
├──35. precedingSibs
├──36. preceding_sib_paths
├──37. preceding_sibs
├──38. followingSibPaths
├──39. followingSibs
├──40. following_sib_paths
├──41. following_sibs
├──42. lcin_path
├──43. lcin
├──44. rcin_path
├──45. rcin
├──46. son_paths
├──47. sons
├──48. total
├──49. maxLevelWidth
├──50. depth
├──51. flatWidth


elist functions


├──0. select_some
├──1. select_seqs
├──1. select_seqs_not
├──1. seqs_not
├──1. select_seqs_keep_order
├──1. select_indexes  
├──1. select_odds
├──1. select_evens
├──1. select_interval
├──1. cond_select_all  
├──1. cond_select_all2  
├──1. cond_select_values_all  
├──1. cond_select_values_all2  
├──1. cond_select_indexes_all  
├──1. cond_select_indexes_all2  
├──1. loose_in  
├──1. select_loose_in  
├──1. select_strict_in  
├──1. regex_in  
├──1. select_regex_in  
├──2. append
├──3. append_some
├──4. prepend
├──5. prepend_some
├──5. unshift
├──6. extend
├──6. push
├──7. concat
├──7. concat_some
├──7. concat_seqs
├──8. prextend
├──9. car
├──10. cdr
├──11. cons
├──12. insert
├──13. insert_some
├──14. insert_many
├──14. insert_section
├──14. insert_sections_some
├──14. insert_sections_many
├──14. reorder_sub
├──14. sort
├──15. batsorted
├──15. batexec
├──15. sortDictList
├──15. lcstr
├──15. sortDictList2
├──16. index_first
├──17. array_index
├──18. indexOf
├──19. index_firstnot
├──20. array_indexnot
├──21. indexOfnot
├──22. index_last
├──24. lastIndexOf
├──25. index_lastnot
├──26. lastIndexOfnot
├──27. index_which
├──28. index_whichnot
├──29. indexes_all
├──30. indexes_allnot
├──31. indexes_some
├──32. indexes_somenot
├──33. indexes_seqs
├──34. indexes_seqsnot
├──35. first_continuous_indexes_slice
├──36. first_continuous_indexesnot_slice
├──37. last_continuous_indexes_slice
├──38. last_continuous_indexesnot_slice
├──39. which_continuous_indexes_slice
├──40. which_continuous_indexesnot_slice
├──41. some_continuous_indexes_slices
├──42. some_continuous_indexesnot_slices
├──43. seqs_continuous_indexes_slices
├──44. seqs_continuous_indexesnot_slices
├──45. all_continuous_indexes_slices
├──46. all_continuous_indexesnot_slices
├──47. shift
├──48. pop
├──48. cond_pop
├──49. pop_range
├──50. pop_some
├──51. pop_indexes
├──52. array_remove
├──53. remove_first
├──54. array_removenot
├──55. remove_firstnot
├──56. remove_last
├──57. remove_lastnot
├──58. remove_which
├──59. remove_whichnot
├──60. remove_some
├──61. remove_somenot
├──62. remove_seqs
├──63. remove_seqsnot
├──64. remove_all
├──65. remove_allnot
├──66. remove_many
├──67. remove_manynot
├──67. cond_remove_all
├──67. cond_remove_seqs
├──67. cond_remove_some
├──68. init
├──68. initWith
├──68. init_range
├──68. initRange
├──69. intlize
├──70. strlize
├──71. array_from
├──72. array_of
├──73. deepcopy
├──74. copy_within
├──75. copyWithin
├──76. reverse
├──77. comprise
├──78. entries
├──79. includes
├──80. toString
├──81. toSource
├──82. splice
├──83. slice
├──84. join
├──85. join2
├──86. htmljoin
├──87. uniqualize
├──87. cond_uniqualize<0>
├──87. cond_uniqualize<1>
├──88. interleave
├──89. for_each
├──90. forEach
├──91. some
├──92. every
├──92. every2
├──93. fill
├──94. filter
├──94. filter2
├──95. find_first
├──96. find
├──97. find_firstnot
├──98. findnot
├──99. find_last
├──100. find_lastnot
├──101. find_which
├──102. find_whichnot
├──103. find_seqs
├──104. find_some
├──105. find_seqsnot
├──106. find_somenot
├──107. find_all
├──107. find_all2
├──108. find_allnot
├──109. array_map
├──110. array_map2
├──111. array_dualmap
├──112. array_dualmap2
├──112. mapfivo(ol,**kwargs)
├──112. mapfiv(ol,map_func_args,**kwargs)
├──112. mapfio(ol,**kwargs)
├──112. mapfvo(ol,**kwargs)
├──112. mapivo(ol,map_func,**kwargs)
├──112. mapfi(ol,map_func_args,**kwargs)
├──112. mapfv(ol,map_func_args,**kwargs)
├──112. mapfo(ol,**kwargs)
├──112. mapiv(ol,map_func,map_func_args)
├──112. mapiv2(ol,map_func,*args,**kwargs)
├──112. mapio(ol,map_func,**kwargs)
├──112. mapvo(ol,map_func,**kwargs)
├──112. mapf(ol,map_func_args,**kwargs)
├──112. mapi(ol,map_func,map_func_args)
├──112. mapv(ol,map_func,map_func_args)
├──112. mapv_inplace(ol,map_func,map_func_args)
├──112. mapo(ol,map_func,**kwargs)
├──113. reduce_left
├──114. array_reduce
├──115. reduceLeft
├──116. reduce_right
├──117. reduceRight
├──118. diff_indexes
├──119. diff_values
├──120. same_indexes
├──121. same_values
├──122. value_indexes_mapping
├──122. cond_value_indexes_mapping
├──123. getitem_via_pathlist
├──124. getitem_via_pathlist2
├──125. getitem_via_sibseqs
├──126. setitem_via_pathlist
├──127. setitem_via_sibseqs
├──128. delitem_via_pathlist
├──129. delitem_via_sibseqs
├──130. is_leaf
├──131. replace_seqs
├──132. replace_some
├──133. replace_value_some
├──134. replace_value_seqs
├──134. cond_replace_value_all
├──134. cond_replace_value_seqs
├──134. cond_replace_value_some
├──135. rangize
├──135. rangize_supplement
├──135. rangize_fullfill
├──135. range_compress
├──135. range_decompress
├──136. broken_seqs
├──137. broken_some
├──137. brkl2kvlist
├──137. refl_vgroupi
├──137. refl_vgroupv
├──137. refl_brkseqs
├──137. vgroupi_brkseqs
├──137. vgroupi
├──137. groupby_refl
├──137. groupby_attr_lngth
├──137. groupby_value_lngth
├──137. groupby_lngth
├──137. divide
├──137. chunk
├──138. classify
├──139. classifyDictList
├──140. split
├──141. where
├──142. where_index_interval
├──143. index_interval
├──142. where_value_interval
├──143. value_interval
├──144. upper_bound
├──145. lower_bound
├──146. matrix_map
├──146. is_matrix
├──146. transpose
├──147. mat2wfs
├──148. wfs2mat
├──149. wfsmat2dfs
├──150. dfs2wfsmat
├──151. wfs2dfs
├──152. dfs2wfs
├──153. get_dfs
├──154. get_wfsmat
├──155. get_wfs
├──156. rand_some_indexes
├──157. rand_sub
├──158. repeat_every
├──159. reindex
├──159. iswap
├──159. vswap
├──160. union
├──161. intersection
├──161. strict_seq_intersection
├──162. difference
├──162. combinations
├──162. recordize
├──162. unrecordize_v
├──162. unrecordize_orig_seq
├──162. recordize_wrapper
├──162. fcp
├──162. l2descl
├──162. find_fst_cmmnval_index
├──162. find_fst_cmmnval
├──162. find_fst_indexpair_fstltsnd_via_reversing
├──162. find_fst_valuepair_fstltsnd_via_reversing
├──162. find_fst_index_gt_via_reversing(value,arr)
├──162. swap(i,j,arr)
├──162. find_fst_index_lt_via_reversing
├──162. find_fst_indexpair_fstgtsnd_via_reversing
├──162. find_fst_valuepair_fstgtsnd_via_reversing
├──162. padding
├──162. prepadding
├──162. find_fst_index_eq_via_reversing
├──162. find_which_index_eq_via_reversing
├──162. find_lst_index_eq_via_reversing
├──162. value_find_range_i
├──162. value_find_range_v
├──162. value_find_range_iv
├──162. interval_sizes2brks
├──162. which_interval(val,intervals)
├──162. which_interval_index(val,intervals)
├──162. find_fst_index_eq
├──162. vidict
├──162. vildict
├──162. groupv_via_same
├──162. groupi_via_same
├──162. group_range_via_same
├──162. el2iteml(el,k)
├──162. el2attrl(el,attr)