Sorry if the obvious question is, I'm new and my google-fu didn't help me.
I am writing a tool that searches for text for alliteration. I have a multidimensional list: [[e, a, c, h], [w, o, r, d], [l, o, o, k, s], [l, i, k, e], [ t, h, i, s]]
I want to iterate over the items in the main list, checking the index [0] of each item to see if it is equal to the index [0] of the FOLLOWING element.
def alit_finder(multi_level_list):
for i in multi_level_list:
if i[0] == multi_level_list[i + 1][0] and i != multi_level_list[-1]:
print i, multi_level_list[i + 1]
I get TypeError: can only a list of concatenations (and not "int") for the list.
So, [i + 1] is not the right way to indicate "an element that has an index equal to i plus one." However, [+ 1] does not work: it seems to return ANY two words in the list that have the same letter in the word [0].
How can I refer to the "next element" in the instructions for this?
ETA: Thanks everyone! I appreciate your time and explanations regarding what I did wrong here!