I'm trying to create a very simple guitar tab creator in python, I had the idea but i'm not sure how to execute it the way I want. For example, I have a list containing each guitar string as a different item in the list, and I want the the user to be able to input which fret they want to use and which note. How can I replace a specific char in a list item based on a index number.
This is what I have so far:
tab = ['E|------------', 'B|------------', 'G|------------', 'D|------------', 'A|------------', 'E|------------']
for line in tab:
print(line)
fret = input("Fret: ")
note = input("Note: ")
#if note == 'E':
(Stuck here)
The output I'm looking for is something like:
e|-------5-7-----7-|-8-----8-2-----2-|-0---------0-----|-----------------|
B|-----5-----5-----|---5-------3-----|---1---1-----1---|-0-1-1-----------|
G|---5---------5---|-----5-------2---|-----2---------2-|-0-2-2---2-------|
D|-7-------6-------|-5-------4-------|-3---------------|-----------------|
A|-----------------|-----------------|-----------------|-2-0-0---0--/8-7-|
E|-----------------|-----------------|-----------------|-----------------|
I am aware that there is much more needed to get the output i'm looking for, but I want to try to figure that stuff out by myself first, I'm just looking for a nudge in the right direction to get a list item changed.
strings don't support item assignment through indexing, so it might be inconvenient to have each string as an actual string instead of a list of characters. You could convert them to lists and use indexing to replace a character through assignment, so directly from your example:tmp = list(tab[0])[fret]=note, convert it back to a string withnew_string = "".join(tmp)fret = "D|"+("-"*1)+"7"+("-"*7)+"6"+("-"*7)?