-
Notifications
You must be signed in to change notification settings - Fork 0
/
listFct.py
executable file
·100 lines (88 loc) · 2.31 KB
/
listFct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
from random import choice
def range (liste, start=0, end=0, step=1):
# end peut valoir -1
lenList = len (liste)
if lenList ==0: return []
while end <=0: end += lenList
if end > lenList: end = lenList
newList =[]
while start <end:
newList.append (start)
start += step
return newList
def iterate (liste, function):
rangeList = range (liste)
newList =[]
for i in rangeList: newList.append (function (liste[i]))
return newList
def sortFunc (liste, funcSort):
if len (liste) <2: return liste
listStart =[]
listEnd =[]
item = choice (liste)
for l in liste:
if funcSort (item, l): listEnd.append (l)
else: listStart.append (l)
if len (listStart) >1: sortFunc (listStart, funcSort)
if len (listEnd) >1: sortFunc (listEnd, funcSort)
newList =[]
if listStart: newList.extend (listStart)
if listEnd: newList.extend (listEnd)
return newList
def comparer (listA, listB):
if len (listA) != len (listB): print ('les données sont de taille différente')
listCommon =[]
listA.sort()
listB.sort()
rangeA = range (listA)
bd =0
for a in rangeA:
if listA[a] in listB[bd:]:
bf = listB.index (listA[a], bd)
while bd < bf:
listCommon.append ((listB[bd], 'b'))
bd +=1
# listCommon.append ((listA[a], 'c'))
bd +=1
else: listCommon.append ((listA[a], 'a'))
rangeB = range (listB, bd)
for b in rangeB: listCommon.append ((listB[b], 'b'))
return listCommon
def copy (liste):
newList =[]
newList.extend (liste)
return newList
def fromText (text, word):
newList = text.split (word)
return newList
def toText (liste, word):
newList =""
for item in liste: newList = newList + word + item
newList = newList.replace (word, "", 1)
return newList
def toTextList (liste):
newList =[]
for item in liste: newList.append (str (item))
return newList
def col (liste, colId):
# pour les tableaux
newList =[]
for line in liste:
if len (line) > colId: newList.append (line[colId])
else: newList.append (None)
return newList
def testIterate (text):
return 'e '+ text
def test():
liste =[ 'a', 'b', 'c', 'd', 'e']
text = toText (liste, ' ')
liste = fromText (text, ' ')
print ('toText\t', text)
print ('fromText\t', liste)
liste =[ 1,3,4]
liste = toTextList (liste)
print ('toTextList\t', liste)
liste = iterate (liste, testIterate)
print ('iterate\t', liste)