{"id":10123,"date":"2021-09-30T12:00:21","date_gmt":"2021-09-30T06:30:21","guid":{"rendered":"https:\/\/python-programs.com\/?p=10123"},"modified":"2021-11-22T18:34:40","modified_gmt":"2021-11-22T13:04:40","slug":"python-program-to-create-a-class-and-get-all-possible-subsets-from-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-create-a-class-and-get-all-possible-subsets-from-a-list\/","title":{"rendered":"Python Program to Create a Class and Get All Possible Subsets from a List"},"content":{"rendered":"

Want to excel in java coding? Practice with these Java Programs examples with output<\/a> and write any kind of easy or difficult programs in the java language<\/p>\n

Object-Oriented Programming(OOPS):<\/strong><\/p>\n

Object-Oriented Programming (OOP) is a programming paradigm based on the concepts of classes and objects. It is used to organize a software program into simple, reusable code blueprints (typically referred to as classes), which are then used to build individual instances of objects. Object-oriented programming languages include JavaScript, C++, Java, and Python, among others.<\/p>\n

A class is a generic blueprint that can be used to generate more specific, concrete things. Classes are frequently used to represent broad groups, such as Cars or Dogs, that share property. These classes indicate what properties, such as color, an instance of this type will have, but not the value of those attributes for a specific object.<\/p>\n

An object comprises data, such as the raw or preprocessed materials at each step of an assembly line, as well as behavior, such as the action performed by each assembly line component.<\/p>\n

Python, like other general-purpose programming languages, has always been an object-oriented language. It enables us to create a program with an Object-Oriented approach. Classes and objects are simple to build and utilize in Python.<\/p>\n

Lists in Python:<\/strong><\/p>\n

In Python, a list is a data structure that works as a container for several values. A Python list is an ordered sequence of values that can be added to, deleted from, and replaced with new values. As a result, a list in Python can expand and contract in size. Each item in a list is referred to as an element, a list item, or simply an item.<\/p>\n

Given a list, the task is to print all the subsets of the given list using classes.<\/p>\n

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

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

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

given list = [4, 19, 2, 5, 3]<\/pre>\n

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

Subsets of the given list [4, 19, 2, 5, 3] :\r\n[[], [19], [5], [5, 19], [4], [4, 19], [4, 5], [4, 5, 19], [3], [3, 19], [3, 5], [3, 5, 19], [3, 4], [3, 4, 19], [3, 4, 5], [3, 4, 5, 19],\r\n [2], [2, 19], [2, 5], [2, 5, 19], [2, 4], [2, 4, 19], [2, 4, 5], [2, 4, 5, 19], [2, 3], [2, 3, 19], [2, 3, 5], [2, 3, 5, 19], [2, 3, 4], \r\n[2, 3, 4, 19], [2, 3, 4, 5], [2, 3, 4, 5, 19]]<\/pre>\n

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

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

given list = ['hello', 'this', 'is', 'btechgeeks']<\/pre>\n

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

Subsets of the given list ['hello', 'this', 'is', 'btechgeeks'] :\r\n[[], ['this'], ['is'], ['is', 'this'], ['hello'], ['hello', 'this'], ['hello', 'is'], ['hello', 'is', 'this'], ['btechgeeks'], ['btechgeeks', 'this'],\r\n ['btechgeeks', 'is'], ['btechgeeks', 'is', 'this'], ['btechgeeks', 'hello'], ['btechgeeks', 'hello', 'this'], ['btechgeeks', 'hello',\r\n 'is'], ['btechgeeks', 'hello', 'is', 'this']]<\/pre>\n

Program to Create a Class and Get All Possible Subsets from a List in Python<\/h2>\n

Below are the ways to print all the subsets of the given list using classes in Python.<\/p>\n

i)Integer List<\/h3>\n

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