5.10.1 Esempi

La funzione bisect() generalmente è utile per classificare dati numerici. Questo esempio utilizza bisect() per valutare con una scala in lettere un esame scolastico classificato con risultati numerici: 'A' significa oltre 85, 'B' da 75 a 84, ecc.

>>> grades = "FEDCBA"
>>> breakpoints = [30, 44, 66, 75, 85]
>>> from bisect import bisect
>>> def grade(total):
...           return grades[bisect(breakpoints, total)]
...
>>> grade(66)
'C'
>>> map(grade, [33, 99, 77, 44, 12, 88])
['E', 'A', 'B', 'D', 'F', 'A']
Vedete Circa questo documento... per informazioni su modifiche e suggerimenti.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy