Hi there

Im doing a project at the moment and need to find the numbers 1,2 and 3 i(all) in any order entered by the user.

A=[]
B=[0,1,2,3,4]
lengthOfList = int(input("Enter the number of elements:"))

for i in range(0,lengthOfList):
elm = int(input("Enter and element value: "))
A.append(elm)

print(A)

Code so far, just need help with the functions

Regards

Paul

In psuedo code something like:
if 1 in B and 2 in B and 3 in B do something.

Looks like you need something like this one liner to test for that.

Thank for this code.

I have tried it and it nearly works, but if you do two of the three numbers, it returns a yes.

All need all three to be present.

Thank you

You could use

if all(x in A for x in (1, 2, 3)):

or

if set((1, 2, 3)).issubset(A):

or

if 3 == len(set(range(1, 4)) & set(A)):

This smells like (not teen spirit) sets! Have a look on sets and Python and I guess your problems will be solved. Success!

@Paul. I gave psuedo code. Let's see your line of code that resulted from that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.