correct expand_list and add notes
This commit is contained in:
parent
2916c23839
commit
0423412e6b
35
calculus.py
35
calculus.py
@ -114,7 +114,7 @@ def computePostfixBis(postfixExp):
|
|||||||
del tokenList[0]
|
del tokenList[0]
|
||||||
tmpTokenList += tokenList
|
tmpTokenList += tokenList
|
||||||
|
|
||||||
tokenList = tmpTokenList.copy()
|
tokenList = expand_list(tmpTokenList)
|
||||||
print(postfixToInfix(" ".join(tokenList)))
|
print(postfixToInfix(" ".join(tokenList)))
|
||||||
|
|
||||||
return tokenList[0]
|
return tokenList[0]
|
||||||
@ -237,9 +237,13 @@ def expand_list(list_list):
|
|||||||
|
|
||||||
>>> expand_list([1,2,[3,4],5,[6,7,8]])
|
>>> expand_list([1,2,[3,4],5,[6,7,8]])
|
||||||
[[1, 2, 3, 5, 6], [1, 2, 4, 5, 7], [1, 2, 4, 5, 8]]
|
[[1, 2, 3, 5, 6], [1, 2, 4, 5, 7], [1, 2, 4, 5, 8]]
|
||||||
|
>>> expand_list([1,2,4,5,6,7,8])
|
||||||
|
[1, 2, 4, 5, 6, 7, 8]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
list_in_list = [i for i in list_list if type(i) == list].copy()
|
list_in_list = [i for i in list_list if type(i) == list].copy()
|
||||||
|
|
||||||
|
try:
|
||||||
nbr_ans_list = max([len(i) for i in list_in_list])
|
nbr_ans_list = max([len(i) for i in list_in_list])
|
||||||
|
|
||||||
ans = [list_list.copy() for i in range(nbr_ans_list)]
|
ans = [list_list.copy() for i in range(nbr_ans_list)]
|
||||||
@ -247,6 +251,9 @@ def expand_list(list_list):
|
|||||||
for (j,e) in enumerate(l):
|
for (j,e) in enumerate(l):
|
||||||
if type(e) == list:
|
if type(e) == list:
|
||||||
ans[i][j] = e[min(i,len(e)-1)]
|
ans[i][j] = e[min(i,len(e)-1)]
|
||||||
|
# S'il n'y a pas eut d'étapes intermédiaires (2e exemple)
|
||||||
|
except ValueError:
|
||||||
|
ans = list_list
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
@ -297,25 +304,25 @@ if __name__ == '__main__':
|
|||||||
#exp = "2 * ( 2 - ( 3 + 4 ) ) + 5 * ( 3 - 4 )"
|
#exp = "2 * ( 2 - ( 3 + 4 ) ) + 5 * ( 3 - 4 )"
|
||||||
#test(exp)
|
#test(exp)
|
||||||
#
|
#
|
||||||
#exp = "2 + 5 * ( 3 - 4 )"
|
exp = "2 + 5 * ( 3 - 4 )"
|
||||||
#test(exp)
|
test(exp)
|
||||||
#
|
|
||||||
#exp = "( 2 + 5 ) * ( 3 - 4 )"
|
exp = "( 2 + 5 ) * ( 3 - 4 )"
|
||||||
#test(exp)
|
test(exp)
|
||||||
#
|
|
||||||
#exp = "( 2 + 5 ) * ( 3 * 4 )"
|
exp = "( 2 + 5 ) * ( 3 * 4 )"
|
||||||
#test(exp)
|
test(exp)
|
||||||
#
|
|
||||||
#exp = "( 2 + 5 ) / ( 3 * 4 )"
|
exp = "( 2 + 5 ) / ( 3 * 4 )"
|
||||||
#test(exp)
|
test(exp)
|
||||||
|
|
||||||
#print(expand_list([1,2,['a','b','c'], 3, ['d','e']]))
|
#print(expand_list([1,2,['a','b','c'], 3, ['d','e']]))
|
||||||
|
|
||||||
## Ce denier pose un soucis. Pour le faire marcher il faudrai implémenter le calcul avec les fractions
|
## Ce denier pose un soucis. Pour le faire marcher il faudrai implémenter le calcul avec les fractions
|
||||||
#exp = "( 2 + 5 ) / 3 * 4"
|
#exp = "( 2 + 5 ) / 3 * 4"
|
||||||
#test(exp)
|
#test(exp)
|
||||||
import doctest
|
#import doctest
|
||||||
doctest.testmod()
|
#doctest.testmod()
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
6
notes
Normal file
6
notes
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Soucis:
|
||||||
|
-> Travailler avec des strings c'est nul faut que ça change.
|
||||||
|
-> Les prints c'est encore plus moche il faut encore plus que ça change
|
||||||
|
|
||||||
|
Idées farfelues:
|
||||||
|
-> Surcharger le __truediv__ des entiers pour creer des fractions ça rendra la chose plus belle et plus simple à utiliser.
|
Loading…
Reference in New Issue
Block a user