0

This is my first post so please give me feedback on how I can format my future questions. I am having trouble understanding this code I recently found. Could someone explain this code segment to me and how it works? I had trouble finding it on Google.

def iterate(sequence: str) -> str: # <- What does (variable: type) -> type do?
    sequence = sequence+R+swapLetters(sequence[::-1])
    return sequence


def swapLetters(sequence: str) -> str: # <- What does (variable: type) -> type do?
    newSequence = ""
    for letter in sequence:
        if letter == R:
            newSequence = newSequence + L
        else:
            newSequence = newSequence + R
    return newSequence


def dragon(n_iterations: int) -> str: # <- What does (variable: type) -> type do?
    initial_sequence = R
    for i in range(0, n_iterations):
        initial_sequence = iterate(initial_sequence)
    return initial_sequence

I am talking about the parameter in all of the functions.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • Welcome to Stack Overflow! Check out the [tour] and [How to ask a good question](/help/how-to-ask) :) – wjandrea Oct 18 '22 at 22:55
  • 1
    What makes you say the parameter is changing type? Did you think the arrow meant the parameter would be converted in some way or another? – wjandrea Oct 18 '22 at 22:56
  • In the future, please see [ask] and the [help] for information on how to structure questions. Currently, your question is very vague. The title doesn't seem to have any obvious relation to the text in the question. Please explain *exactly* what it is you want to understand. Also, in general, you are expected to do some basic research before asking a question -- google for other stack overflow questions is always a good start – juanpa.arrivillaga Oct 18 '22 at 23:25

0 Answers0