Esempio filtro test

master
Guido Longoni 2019-09-27 14:28:50 +02:00
parent 4665bff0ef
commit f6cb45b954
1 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 27 11:21:37 2019
@author: Guido Longoni - guidolongoni@gmail.com
"""
regole = [
(lambda x: isinstance(x, int) and x > 0, 'è un intero positivo'),
(lambda x: isinstance(x, int) and x < 0, 'è un intero negativo'),
(lambda x: isinstance(x, float) and x > 0, 'è un reale positivo'),
(lambda x: isinstance(x, float) and x < 0, 'è un reale negativo'),
(lambda x: True, 'non è un numero'),
]
test = [1,-1,'ciao',3.14,-0.5]
risultato_filtro = [str(dato)+' '+next(regola[1] for regola in regole if regola[0](dato)) for dato in test]