May-20-2020, 12:12 PM
(This post was last modified: May-20-2020, 12:13 PM by hussainmujtaba.)
One way can go through each item in the list with a loop and compare them to your sum, but this is not an efficient way to do. So I guess you should go with the answer of Menator01 with a slight modification. It is more efficient if you convert your list to a set just for comparison purpose. A list can have the same element multiple times, when converting it to a set, it ll only contain element once. Thus the search space has decreased and it 'll be faster.
sum = 33 list1=[11,22,33,44,55] if sum in set(list1): print(f'{sum} is in list') else: print(f'{sum} is not in list')