{"id":3670,"date":"2023-10-23T19:28:58","date_gmt":"2023-10-23T13:58:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=3670"},"modified":"2023-11-10T11:55:10","modified_gmt":"2023-11-10T06:25:10","slug":"python-check-if-a-list-contains-all-the-elements-of-another-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-check-if-a-list-contains-all-the-elements-of-another-list\/","title":{"rendered":"Python : Check if a List Contains all the Elements of Another List"},"content":{"rendered":"

In Python, the list datatype\u00a0is that the\u00a0<\/span>most versatile, and it\u00a0are often\u00a0<\/span>written as\u00a0an inventory\u00a0<\/span>of comma-separated values (items) enclosed in square brackets.<\/p>\n

Given two lists, the task is to check whether the second list has all the elements of first list.<\/p>\n

Examples:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

\n
givenlist1 = <\/span>[<\/span>'Hello'<\/span> , <\/span>'this'<\/span>, <\/span>'is'<\/span>, <\/span>'Btech'<\/span>, <\/span>'Geeks'<\/span>]\r\n<\/span>givenlist2 = [<\/span>'Btech','Geeks'<\/span>]<\/span><\/pre>\n<\/div>\n
\n
Output:<\/strong><\/div>\n
givenlist2\u00a0has\u00a0all of the \u00a0givenlist1\u00a0elements<\/pre>\n<\/div>\n

Input:<\/strong><\/p>\n

\n
givenlist1 = <\/span>[<\/span>'Hello'<\/span> , <\/span>'this'<\/span>, <\/span>'is'<\/span>, <\/span>'Btech'<\/span>, <\/span>'Geeks'<\/span>]\r\n<\/span>givenlist2 = [<\/span>'Btech','Geeks','pink'<\/span>]<\/span><\/pre>\n<\/div>\n
\n
Output:<\/strong><\/div>\n
givenlist2 doesn't have all of the \u00a0givenlist1 elements<\/pre>\n<\/div>\n

Determine whether \u00a0a list is included inside another list<\/h2>\n

There are several ways to check if a list is contained in another list some of them are:<\/p>\n