I have the following working code for Python I produced. It´s a rewriting system based on Lindenmayer. The Output C is: +-LF+RFR+FL-F-+RF-LFL-FR+F+RF-LFL-FR+-F-LF+RFR+FL-+
which I can interpret to draw a space-filling curve. C is the starting letter and the process is performed n times.
C = 'L'
n = 2
Code = {ord('L'):'+RF-LFL-FR+',
ord('R'):'-LF+RFR+FL-'}
while n:
C = C.translate(Code)
n -=1
print C
Now I want, that the code is written automatically from a list. For example I have the list R=[['L', '+RF-LFL-FR+'], ['R', '-LF+RFR+FL-']]
which should be automatically inserted in the code, so I can use it furthermore. The first element of every sub-list should be inserted in the ord()
method and the second after the colon. Any suggestions?
I found a way via list comprehension. The List R is L=+RF-LFL-FR+, R=-LF+RFR+FL-
. Now I ask if theres a more efficient way to get to the code?
R = ['L=+RF-LFL-FR+','R=-LF+RFR+FL-']
A = 'L'
for i in range(0,len(R)):
R[i]=R[i].split('=')
print R
Start = []
Rule = []
for i in range(0,len(R)):
Start.append(R[i][0])
Rule.append(R[i][1])
#mapping via list comprehension
while n:
A=''.join([Rule[Start.index(i)] if i in Start else i for i in A])
n -=1
print A