PYTHON tuple working

Programe is:

#
#  Tuple
#   
from operator import itemgetter
Workers = [
           ('POPESCU Gheorghe',   32,     3200, 'Assembly    '),
           ('IONESCU Dumitru ',   40,     4100, 'Mechanics   '),
           ('GRIGORECU Ion   ',   27,     2930, 'Tinware     '),
           ('GRIGORIU Georgel',   37,     3935, 'Warehouseman')]
print(' ******** Initial tuple *****  ')
Worker_number = len(Workers) # Tuple number
i = 0
ALFA  = ('Worker name ','Age', 'Salary', 'Work place  ')
print( ALFA)
while i < Worker_number:
    print( Workers[i ])
    i = i + 1
print('Workers number is:', Worker_number -1)
i = 0
while i < Worker_number:
    print( Workers[i ][0])
    i = i + 1
i = 1
Total_salary = 0
while i < Worker_number:
    Total_salary = Total_salary + int(Workers[i ][2])
    i = i + 1
print('Total salary  is:', Total_salary)
i = 0
while i < Worker_number:
    print( Workers[i ])
    i = i + 1
Workers.sort(key=itemgetter(0))  # Sort by name
print('   ')
i = 0
while i < Worker_number:
    print( Workers[i ])
    i = i + 1
Workers.sort(key=itemgetter(1))  # Sort by age
print(' ******** Sort by age *****  ')
i = 0
while i < Worker_number:
    print( Workers[i ])
    i = i + 1
Workers.sort(key=itemgetter(2))  # Sort by salary
print(' ******* Sort by salary ********   ')
i = 0
while i < Worker_number:
    print( Workers[i ])
    i = i + 1
Workers.sort(key=itemgetter(3))  # Sort by work place
print(' ********* Sort by work place *************  ')
i = 0
while i < Worker_number:
    print( Workers[i ])
    i = i + 1

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/TupleWorkers.py ==============
 ******** Initial tuple *****  
('Worker name ', 'Age', 'Salary', 'Work place  ')
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')
Workers number is: 3
POPESCU Gheorghe
IONESCU Dumitru 
GRIGORECU Ion   
GRIGORIU Georgel
Total salary  is: 10965
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')
   
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
 ******** Sort by age *****  
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
 ******* Sort by salary ********   
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
 ********* Sort by work place *************  
('POPESCU Gheorghe', 32, 3200, 'Assembly    ')
('IONESCU Dumitru ', 40, 4100, 'Mechanics   ')
('GRIGORECU Ion   ', 27, 2930, 'Tinware     ')
('GRIGORIU Georgel', 37, 3935, 'Warehouseman')

(March 23, 2022)

     

Comments

Popular posts from this blog

Pointers in PYTHON?

Generates M prime numbers