I tried to create a function that accommodates and uses every element in a list at the same time, and the number of elements in a list is the user input. That means it varies from time to time. It can be a list of 3 elements or 4 elements or whatever is the number. It's kinda abstract. I will illustrate it with some code.
Assume that I want to see if the 2 alphabets in list A are in B.
A = ['a', 'b']
B = 'apple'
if A[0] in B and A[1] in B:
print (f'{A[0]} and {A[B]} are in {B}!')
else:
print (f'{A[0]} or {A[1]} is not in {B}!')
But if I want to accommodate another situation that the number of alphabets is 3? I can't think of a better way but to make it redundant like this.
A = ['a', 'b', 'c']
B = 'apple'
if len(A) == 2:
if A[0] in B and A[1] in B:
print (f'{A[0]} and {A[1]} are in {B}!')
else:
print (f'{A[0]} or {A[1]} is not in {B}!')
elif len(B) == 3:
if A[0] in B and A[1] in B and A[2] in B:
print (f'{A[0]}, {A[1]}, and {A[2]} are in {B}!')
else:
print (f'{A[0]}, {A[1]}, or {A[3]} is not in {B}!')
And actually I am building a solver for the famous game Wordle, so you can foresee that because of the length of words in Wordle, I have the if statement from len(A) == 1 to len(A) == 5. That is pretty lengthy. I know there is a bunch of Wordle solvers on the Internet, but I am just trying to make a project on my own and, as a newbie coder, practice my coding skills. Thanks for helping me out in advance.