|
| 1 | +from functools import cmp_to_key |
| 2 | + |
| 3 | +agenda_hospital = [] |
| 4 | + |
| 5 | +persona = ('Juan', 'Mora', 100103111, 65, 81118811, 'dolor') |
| 6 | + |
| 7 | +agenda_hospital.append(persona) |
| 8 | + |
| 9 | +persona = ('Ana', 'Jiminez', 32415116, 50, 46261266, 'consulta') |
| 10 | + |
| 11 | +agenda_hospital.append(persona) |
| 12 | + |
| 13 | +persona = [('Sofia', 'Alfaro', 32415116, 36, 51161161, 'consulta'), |
| 14 | + ('Carlos', 'Sanchez', 33411151, 15, 41655161, 'dolor'), |
| 15 | + ('Felipe', 'Perez', 12243151, 42, 65151111, 'documento'), |
| 16 | + ('Melissa', 'Alvaro', 734114144, 10, 87421612, 'dolor'), |
| 17 | + ('Pedro', 'Castro', 4372124141, 2, 99313131, 'dolor')] |
| 18 | + |
| 19 | +agenda_hospital.extend(persona) |
| 20 | + |
| 21 | +print("El total de Pacientes es: {0}".format(len(agenda_hospital))) |
| 22 | + |
| 23 | +cantidad_pacientes_dolor = 0 |
| 24 | +for paciente in agenda_hospital: |
| 25 | + if paciente[5] == 'dolor': |
| 26 | + cantidad_pacientes_dolor += 1 |
| 27 | + |
| 28 | +print("EL total de Pacientes con dolor es: {0}".format(cantidad_pacientes_dolor)) |
| 29 | + |
| 30 | +def cmp_tuplas(a, b): |
| 31 | + if a[3] >= b[3]: |
| 32 | + return -1 |
| 33 | + else: |
| 34 | + return 1 |
| 35 | + |
| 36 | + |
| 37 | +clave_ordenacion = cmp_to_key(cmp_tuplas) |
| 38 | + |
| 39 | +agenda_hospital = sorted(agenda_hospital, key=clave_ordenacion) |
| 40 | + |
| 41 | +for paciente in agenda_hospital: |
| 42 | + print(paciente) |
| 43 | + |
| 44 | +personas_menores = 0 |
| 45 | +personas_mayores = 0 |
| 46 | + |
| 47 | +for persona in agenda_hospital: |
| 48 | + if persona[3] >= 18: |
| 49 | + personas_mayores += 1 |
| 50 | + else: |
| 51 | + persona[3] <= 18 |
| 52 | + personas_menores += 1 |
| 53 | + |
| 54 | +print('las personas mayores son: ', personas_mayores) |
| 55 | +print('las personas menores son: ', personas_menores) |
| 56 | + |
0 commit comments