How to select starting letter in a list of letters
I have a list of letters. As of right now, I am able to allocate my starting point based on the index point (IE: 0 = 'A', 1 = 'B', 2 = 'C', etc).
def moving_letters():
letters = ['A','B','C','D','E','F','G']
*user = int(input('Enter starting index #: '))*
print(letters[user], letters[(user + 5) % len(letters)], letters[(user + 7) % len(letters)])
print(moving_letters())
How would I be able to select a specific letter in my list as a starting point?
Also, how would I be able to move my starting point as showed in?:
print(letters[user], letters[(user + 5) % len(letters)],
letters[(user + 7) % len(letters)])
You can select a slice of a list with :
in the index, where you can specify start and end, if either is left empty you select everything. After you have a slice of a list selected, you can use join
to make a line to print. Keep in mind the items you are joining have to be strings.
def moving_letters():
letters = ['A','B','C','D','E','F','G']
user = int(input('Enter starting index #: '))
s = " ".join(letters[user:])
print(s)
moving_letters()
Slice notation: Understanding slice notation
String join: What exactly does the .join() method do?