Q:

How to avoid 'else' in this case?

Is there a better way to do this? A friend told me to avoid else, in order to keep the code clean, but i can't figure out another way to do this.
if listA[0] in listB:
    k = listA[0]
else:
    k = listB[1]

A:

Before the if statement, you could do
k = listB[1]

That way there is no else. The entire block would look like this:
k = listB[1]
if listA[0] in listB:
    k = listA[0]

