Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,285 questions

52,311 answers

573 users

How to check whether a sequential list is a subset of another sequential list in Python

3 Answers

0 votes
list1 = [1, 2, 3]
list2 = [1, 2, 3, 4, 5]

# Check if list1 is a subset of list2
is_subset = set(list1).issubset(set(list2))

print(is_subset)


'''
run:

True

'''

 



answered Mar 24, 2025 by avibootz
0 votes
list1 = [1, 2, 3]
list2 = [1, 2, 3, 4, 5]

# Check if list1 is a subset of list2
is_subset = all(element in list2 for element in list1)

print(is_subset)


'''
run:

True

'''

 



answered Mar 24, 2025 by avibootz
0 votes
list1 = [1, 2, 3]
list2 = [1, 2, 3, 4, 5]

# Check if list1 is a subset of list2
is_subset = True
for element in list1:
    if element not in list2:
        is_subset = False
        break

print(is_subset)


'''
run:

True

'''

 



answered Mar 24, 2025 by avibootz
...