This project shows the difference with a List, Set or Tuple.   It shows what is a string and what is a tuple

List: Lists are just like dynamic sized arrays, declared in other languages (vector in C++ and ArrayList in Java). Lists need not be homogeneous always which makes it the most powerful tool in Python. The main characteristics of lists are – 

  • The list is a datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
  • List are mutable .i.e it can be converted into another data type and can store any data element in it.
  • List can store any type of element.

Set: In Python, Set is an unordered collection of data type that is iterable, mutable, and has no duplicate elements. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set. The main characteristics of set are –

  • Sets are an unordered collection of elements or unintended collection of items In python.
  • Here the order in which the elements are added into the set is not fixed, it can change frequently.
  • It is defined under curly braces{}
  • Sets are mutable, however, only immutable objects can be stored in it.

Tuple: Tuple is a collection of Python objects much like a list. The sequence of values stored in a tuple can be of any type, and they are indexed by integers. Values of a tuple are syntactically separated by ‘commas’. Although it is not necessary, it is more common to define a tuple by closing the sequence of values in parentheses. The main characteristics of tuples are – 

  • Tuple is an immutable sequence in python.
  • It cannot be changed or replaced since it is immutable.
  • It is defined under parenthesis().
  • Tuples can store any type of element.

main.py


#!/usr/bin/env/python3

from List_Commands import *
from Print_Commands import *


def main():
    s = "\'a', 'b', 'c', 'd', 'e\'"
    t = ('a', 'b', 'c', 'd', 'e')
    print(s, 'is a ', type(s), 'because it is enclosed by quotes')
    print(t, 'is a ', type(t), 'because it has ( around it')

    print('')
    print('print each character of the string')
    A = PRINTME(s)
    A.printcommands()
    print('')
    print('')
    print('print each character of the tuple')
    A = PRINTME(t)
    A.printcommands()

    print('')
    print('')
    s1 = ('a',)
    t2 = ('a')
    print(s1, 'is a ', type(s1), 'it ends with a comma')
    print(t2, 'is a ', type(t2))

    print('')
    t3 = tuple('python')
    print(t3, 'is a ', type(t3))
    print("")

    set1 = set()
    print("Initial blank Set: ")
    print(set1)

    # Creating a Set with
    # the use of Constructor
    # (Using object to Store String)
    String = 'Set with Constructor'
    set1 = set(String)
    print("set () method is used to convert any of the iterable to sequence of "
          "iterable elements with distinct elements")
    print("")
    print("my String is {}".format(String))
    print("Set with the use of an Object: ")
    print(set1)
    print("")

    # Creating a Set with
    # the use of a List
    set1 = set(["Ferrari", "Porsche", "Lamborghini"])
    print("\nSet with the use of List: ")
    print(set1)
    print("")

    # zip two lists together
    List3 = ["Ferrari", "Porsche", "Lamborghini"]
    List5 = ["Ferrari", "Porsche", "Lamborghini", "Maserati", "Alfa Romeo"]
    print("List3: {}".format(List3))
    print("List5: {}".format(List5))
    zipped = list(zip(List3, List5))
    print("since List3 is 3 items, it will only match those in the list")
    print("as it is the first list")
    print("List3 and List5 zipped into a list: {}".format(zipped))

# change an item on the list by x with input
    print("")
    print("**************************************")
    List1 = [1, 2, 3, 4]
    A = PRINTME(List1)
    A.printcommands()
    print("")
    print("which item do you want to change and to what")
    first = int(input("variable: "))
    changeval = input("change it to what: ")
    List1[first] = changeval
    A = PRINTME(List1)
    A.printcommands()

# extend the list by x variables with inputs
    print("")
    print("********************************")
    print("This is to extend a list by")
    print("print from class PrintOut")
    A = PRINTME(List1)
    A.printcommands()

    B = EXTEND(List1)
    B.whichcommands()

    A = PRINTME(List1)
    A.printcommands()

# pick which variable to change and to what?
    print("")
    print("********************************")
    List1 = [[1, 2, 3, 4], [5, 6, 7, 8]]
    print("print from class Printout")
    A = TWODPRINTME(List1)
    A.printcommands()

    B = REPLACE(List1)
    B.whichcommands()

    A = TWODPRINTME(List1)
    A.printcommands()

# pick which variable to delete
    print("")
    print("*******************")
    print("here is your list ")
    print("print from class Printout")
    A = TWODPRINTME(List1)
    A.printcommands()
    first = 0
    second = 0
    print("which item do you want to delete")
    first = input("first variable: ")
    second = input("second variable: ")
    print("first: {} second:{}".format(first, second))
    A = DELETETWOVAR(List1, first, second)
    A.whichcommands()
    print("")
    print("Here is the list with the removed item")
    B = TWODPRINTME(List1)
    B.printcommands()

# Clear a list
    print("")
    print("*******************")
    print("use .clear() to clear the list")
    print("{}".format(List1))
    A = CLEAR([1, 2, 3, 4, 5, 6, 7, 8])
    A.whichcommands()

# Reverse a list
    print("")
    print("*******************")
    print("make a copy of a list and reverse List1")
    A = REVERSE([1, 2, 3, 4, 5, 6, 7, 8])
    A.whichcommands()

# Maximum in a list
    print("")
    print("*******************")
    print("Maximum value from list")
    A = MAX([12, 1, 13, 2, 3, 4, 5, 6, 7, 8])
    A.whichcommands()
    B = MAX(List1)
    B.whichcommands()

# Minimum in a list
    print("")
    print("*******************")
    print("Minimum value from list")
    A = MIN([12, 1, 13, 2, 3, 4, 5, 6, 7, 8])
    A.whichcommands()
    B = MIN(List1)
    B.whichcommands()

if __name__ == '__main__':
    main()



Print_Commands.py

#!/usr/bin/env/python3

import abc
from abc import ABC


class printcommands(ABC):
    @abc.abstractmethod
    def printcommands(self):
        pass

class PRINTME(printcommands):
    def __init__(self, x):
        self.List1 = x

    def printcommands(self):
        print("{}".format(self.List1))
        print("")
        s = 0
        numoftuples = len(self.List1)
        while s < numoftuples:
            print("{} is {}".format(s, self.List1[s]))
            s += 1

class TWODPRINTME(printcommands):
    def __init__(self, x):
        self.List1 = x

    def printcommands(self):
        print("{}".format(self.List1))
        print("")

        s = 0
        numoftuples = len(self.List1)
        while s < numoftuples:
            t = 0
            itemsintuples = len(self.List1[s])
            while t < itemsintuples:
                print("{}:{} is {}".format(s, t, self.List1[s][t]))
                t += 1
            s += 1

List_Commands.py


#!/usr/bin/env/python3

import abc
from abc import ABC

class listcommnds(ABC):
    @abc.abstractmethod
    def whichcommands(self):
        pass

class CLEAR(listcommnds):
    def __init__(self,x):
        self.List1 = x

    def whichcommands(self):
        self.List1.clear()
        print("cleared List1")
        print("{}".format(self.List1))


class REVERSE(listcommnds):
    def __init__(self,x):
        self.List1 = x

    def whichcommands(self):
        List2 = self.List1.copy()
        List2.reverse()
        print("List1: {}".format(self.List1))
        print("List2: {}".format(List2))


class DELETETWOVAR(listcommnds):
    def __init__(self, x, y, z):
        self.List1 = x
        self.first = int(y)
        self.second = int(z)

    def whichcommands(self):
        del(self.List1[self.first][self.second])


class APPEND(listcommnds):
    def __init__(self, x, y):
        self.List1 = x
        self.y = int(y)

    def whichcommands(self):
        self.List1.append(self.y)

class REPLACE(listcommnds):
    def __init__(self, x):
        self.List1 = x

    def whichcommands(self):
        print("")
        first = int(0)
        second = int(0)
        changeval = int(0)
        print("choose the item to replace and what is the new value")
        first = int(input("first variable: "))
        second = int(input("second variable: "))
        changeval = int(input("change it to what: "))
        self.List1[first][second] = changeval
        print("print from class Printout {}".format(changeval))

class EXTEND(listcommnds):
    def __init__(self, x):
        self.List1 = x

    def whichcommands(self):
        print("")
        howmanyvar = int(input("How many items do you want to extend the list by: "))
        s = 0
        ext_list = []
        while s < howmanyvar:
            addwhat = int(input("what do you want to add {}: ".format(s)))
            ext_list.append(addwhat)
            s += 1
        self.List1.extend(ext_list)

class MAX(listcommnds):
    def __init__(self, x):
        self.List1 = x

    def whichcommands(self):
        print("")
        print("List: {}". format(self.List1))
        print("Max: {}". format(max(self.List1)))

class MIN(listcommnds):
    def __init__(self, x):
        self.List1 = x

    def whichcommands(self):
        print("")
        print("List: {}". format(self.List1))
        print("Min: {}". format(min(self.List1)))
        
        


Output



'a', 'b', 'c', 'd', 'e' is a   because it is enclosed by quotes
('a', 'b', 'c', 'd', 'e') is a   because it has ( around it

print each character of the string
'a', 'b', 'c', 'd', 'e'

0 is '
1 is a
2 is '
3 is ,
4 is  
5 is '
6 is b
7 is '
8 is ,
9 is  
10 is '
11 is c
12 is '
13 is ,
14 is  
15 is '
16 is d
17 is '
18 is ,
19 is  
20 is '
21 is e
22 is '


print each character of the tuple
('a', 'b', 'c', 'd', 'e')

0 is a
1 is b
2 is c
3 is d
4 is e


('a',) is a   it ends with a comma
a is a  

('p', 'y', 't', 'h', 'o', 'n') is a  

Initial blank Set: 
set()
set () method is used to convert any of the iterable to sequence of iterable elements with distinct elements

my String is Set with Constructor
Set with the use of an Object: 
{'n', 'r', 'w', 'u', 'S', ' ', 'e', 'c', 'o', 'h', 's', 'i', 'C', 't'}


Set with the use of List: 
{'Porsche', 'Lamborghini', 'Ferrari'}

List3: ['Ferrari', 'Porsche', 'Lamborghini']
List5: ['Ferrari', 'Porsche', 'Lamborghini', 'Maserati', 'Alfa Romeo']
since List3 is 3 items, it will only match those in the list
as it is the first list
List3 and List5 zipped into a list: [('Ferrari', 'Ferrari'), ('Porsche', 'Porsche'), ('Lamborghini', 'Lamborghini')]

**************************************
[1, 2, 3, 4]

0 is 1
1 is 2
2 is 3
3 is 4

which item do you want to change and to what
variable: 0
change it to what: 12
['12', 2, 3, 4]

0 is 12
1 is 2
2 is 3
3 is 4

********************************
This is to extend a list by
print from class PrintOut
['12', 2, 3, 4]

0 is 12
1 is 2
2 is 3
3 is 4

How many items do you want to extend the list by: 2
what do you want to add 0: 12
what do you want to add 1: 12
['12', 2, 3, 4, 12, 12]

0 is 12
1 is 2
2 is 3
3 is 4
4 is 12
5 is 12

********************************
print from class Printout
[[1, 2, 3, 4], [5, 6, 7, 8]]

0:0 is 1
0:1 is 2
0:2 is 3
0:3 is 4
1:0 is 5
1:1 is 6
1:2 is 7
1:3 is 8

choose the item to replace and what is the new value
first variable: 0
second variable: 0
change it to what: 12
print from class Printout 12
[[12, 2, 3, 4], [5, 6, 7, 8]]

0:0 is 12
0:1 is 2
0:2 is 3
0:3 is 4
1:0 is 5
1:1 is 6
1:2 is 7
1:3 is 8

*******************
here is your list 
print from class Printout
[[12, 2, 3, 4], [5, 6, 7, 8]]

0:0 is 12
0:1 is 2
0:2 is 3
0:3 is 4
1:0 is 5
1:1 is 6
1:2 is 7
1:3 is 8
which item do you want to delete
first variable: 0
second variable: 0
first: 0 second:0

Here is the list with the removed item
[[2, 3, 4], [5, 6, 7, 8]]

0:0 is 2
0:1 is 3
0:2 is 4
1:0 is 5
1:1 is 6
1:2 is 7
1:3 is 8

*******************
use .clear() to clear the list
[[2, 3, 4], [5, 6, 7, 8]]
cleared List1
[]

*******************
make a copy of a list and reverse List1
List1: [1, 2, 3, 4, 5, 6, 7, 8]
List2: [8, 7, 6, 5, 4, 3, 2, 1]

*******************
Maximum value from list

List: [12, 1, 13, 2, 3, 4, 5, 6, 7, 8]
Max: 13

List: [[2, 3, 4], [5, 6, 7, 8]]
Max: [5, 6, 7, 8]

*******************
Minimum value from list

List: [12, 1, 13, 2, 3, 4, 5, 6, 7, 8]
Min: 1

List: [[2, 3, 4], [5, 6, 7, 8]]
Min: [2, 3, 4]

Process finished with exit code 0