Function that adds two items from a list in search of those that will match some given sum I'm doing a Daily Challenges to get better with Python. 
I completed the first challenges with a working code but I want to make sure if there's anyway to improve or optimize it.

I have a function that adds 2 items from a list in search of those that will match the already defined result.

def main():

  listA = [10,11,3,7]
  k = 21 

  for i in listA:
    for e in listA:
      result = i + e
      if result == k:
        print(i, '+', e, ' = ', k)
        return
main() 


I was thinking of reducing it to:


def main():
  k = 21
  listA=[10,11,3,7]
  print (k,'=',[(i and e) for i in listA for e in listA if k==(i+e)])
main()



… but that would print 21 = [10,11] instead of 21 = 10 + 11.
def main():
    k = 21
    listA=[10,11,3,7]
    print (k,' = '," + ".join([str(i and e) for i in listA for e in listA if k==(i+e)]))

main()


This minor change to your code will do what you're after.  Put a " + ".join( ) around your list creator and cast the (i and e) items to str, that will then join all string elements in the list together into a string with + as the separator (there are spaces in there, yes, and this is necessary to get the output you're after).

Proof of Concept (via tio.run) that shows you how this will execute.

Note I also made a change to add spaces around the equals sign, indentation, and extra spacing for readability, as well as indentation standardization (4 spaces for a single indentation level).