Lists operators

#
#        String and lists operations
#
#        len() - components number list
#         +    -  concatenate list operator
#        set() - list conversion în set
#          &   -  intersection operator in setss
String = 'This is a string'
Word_list_A = ['AUDI ', 'FORD ', 'DACIA ', 'TATA', 'RENAULT ', 
               'CITROEN','LAMBORGHINI ', 'FERRARI' , 'VOLKSWAGEN', 
               'ASTON MARTIN''BUICK ', 'ALFA ROMEO ', 'CRYSLER ', 
               'BMW']
Word_list_B = ['LADA', 'SKODA', 'VOLGA', 'TATRA', 'PEUGEOT', 'SAAB',                   'VOLVO','TOYOTA', 'HYUNDAI', 'SUBARU']
Length_A = len(Word_list_A)
Length_B = len(Word_list_B)
print('Element number în A list  is:', Length_A)
print('Element number în B list  is:', Length_B)
print('First list is:', Word_list_A)
print('Second list is:', Word_list_B)
Concatenate_list = Word_list_A + Word_list_B
print('Concatenate list is:', Concatenate_list)
Intersection_list = list(set(Word_list_A) & set( Word_list_B))
print('Intersection list is:', Intersection_list)
Union_list = sorted(list(set(Word_list_A)) + list(set( Word_list_B)))
print('Union list is:', Union_list)
Length_AinterB = len(Intersection_list)
Length_AuniB = len(Union_list)
print('Element number în A intersected by B lists  is:', Length_AinterB)
print('Element number în A union B  lists  is:', Length_AuniB)
Word_list_A.sort()
Word_Asorted = Word_list_A
print('First sorted list is:', Word_Asorted)
Results are:

Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
============== RESTART: /Users/ionivan/Documents/ListOperations.py =============
Element number în A list  is: 13
Element number în B list  is: 10
First list is: ['AUDI ', 'FORD ', 'DACIA ', 'TATA', 'RENAULT ', 'CITROEN ', 'LAMBORGHINI ', 'FERRARI', 'VOLKSWAGEN', 'ASTON MARTINBUICK ', 'ALFA ROMEO ', 'CRYSLER ', 'BMW']
Second list is: ['LADA', 'SKODA', 'VOLGA', 'TATRA', 'PEUGEOT', 'SAAB', 'VOLVO', 'TOYOTA', 'HYUNDAI', 'SUBARU']
Concatenate list is: ['AUDI ', 'FORD ', 'DACIA ', 'TATA', 'RENAULT ', 'CITROEN ', 'LAMBORGHINI ', 'FERRARI', 'VOLKSWAGEN', 'ASTON MARTINBUICK ', 'ALFA ROMEO ', 'CRYSLER ', 'BMW', 'LADA', 'SKODA', 'VOLGA', 'TATRA', 'PEUGEOT', 'SAAB', 'VOLVO', 'TOYOTA', 'HYUNDAI', 'SUBARU']
Intersection list is: []
Union list is: ['ALFA ROMEO ', 'ASTON MARTINBUICK ', 'AUDI ', 'BMW', 'CITROEN ', 'CRYSLER ', 'DACIA ', 'FERRARI', 'FORD ', 'HYUNDAI', 'LADA', 'LAMBORGHINI ', 'PEUGEOT', 'RENAULT ', 'SAAB', 'SKODA', 'SUBARU', 'TATA', 'TATRA', 'TOYOTA', 'VOLGA', 'VOLKSWAGEN', 'VOLVO']
Element number în A intersected by B lists  is: 0
Element number în A union B  lists  is: 23
First sorted list is: ['ALFA ROMEO ', 'ASTON MARTINBUICK ', 'AUDI ', 'BMW', 'CITROEN ', 'CRYSLER ', 'DACIA ', 'FERRARI', 'FORD ', 'LAMBORGHINI ', 'RENAULT ', 'TATA', 'VOLKSWAGEN']

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers