Last active
December 8, 2022 12:18
-
-
Save juanfal/6734ff330b6e204306b9de677531ab56 to your computer and use it in GitHub Desktop.
equipo de baloncesto a dic dic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# leeEquipoBaloncestoDicDic.py | |
# juanfc 2020-01-13 | |
# https://gist.github.com/6734ff330b6e204306b9de677531ab56 | |
# nombre, siempre terminado en coma ‘,’ | |
# - dorsal | |
# - posición: | |
# Base, Escolta, Alero, aLa-pivot, Pivot, | |
# B E A L P | |
# - promedio de puntos (número real) | |
# - promedio de rebotes (número real) | |
# Berni Rodriguez, 5, E, 5.2, 1.7 | |
# Luka Zoric, 21, P, 11.2, 4.8 | |
# {"Berni Rodriguez": | |
# {"dorsal": 5, "posición": 'Escolta', "puntos": 5.2, "rebotes": 1.7} | |
# } | |
def leeFichEquipoBaloncesto(nomFich): | |
""" Lee el fichero y devuelve dict de dict """ | |
r = {} | |
f = open(nomFich) | |
nomCompleto = {'B': 'Base', 'E': 'Escolta', | |
'A': 'Alero', 'L':'aLa-pivot', 'P':'Pivot' } | |
for linea in f: | |
c = linea.split(',') | |
jugaNombre = c[0] | |
dorsal = int(c[1]) | |
pos = c[2].strip() # quitamos espacios alrededor letra | |
puntos = float(c[3]) | |
rebotes = float(c[3]) | |
r[jugaNombre] = { "dorsal": dorsal, | |
"posición": nomCompleto[pos], | |
"puntos": puntos, | |
"rebotes": rebotes | |
} | |
return r | |
def mediaPuntos(equipo): | |
s = 0 | |
for jug in equipo: | |
s += equipo[jug]['puntos'] | |
return s/len(equipo) | |
def maximaPuntuacion(equipo): | |
maximo = 0 | |
for jug in equipo: | |
if equipo[jug]['puntos'] > maximo: | |
maximo = equipo[jug]['puntos'] | |
return maximo | |
def masPuntos(d): | |
""" Devuelve lista de jugadores con más puntos """ | |
# averiguar máxima puntuación | |
m = maximaPuntuacion(d) | |
# volvemos a ver los jugadores | |
# cojemos los jugadores | |
# que tienen _esa_ puntuación máxima | |
r = [] | |
for jug in d: | |
if d[jug]['puntos'] == m: | |
r.append(jug) | |
return r | |
def maximoRebotes(equipo): | |
maximo = 0 | |
for jug in equipo: | |
if equipo[jug]['rebotes'] > maximo: | |
maximo = equipo[jug]['rebotes'] | |
return maximo | |
def masRebotes(d): | |
""" Devuelve lista de jugadores con más rebotes """ | |
# averiguar máxima puntuación | |
m = maximoRebotes(d) | |
# volvemos a ver los jugadores | |
# cojemos los jugadores | |
# que tienen _esa_ puntuación máxima | |
r = [] | |
for jug in d: | |
if d[jug]['rebotes'] == m: | |
r.append(jug) | |
return r | |
def jugadorDeDorsal(equipo, numDorsal): | |
for jugador in equipo: | |
if equipo[jugador]['dorsal'] == numDorsal: | |
return jugador | |
return None | |
def printJugador(equipo, jugador): | |
print("Nombre: ", jugador) | |
print("Dorsal: ", equipo[jugador]['dorsal']) | |
print("Posición: ", equipo[jugador]['posición']) | |
print("Puntos: ", equipo[jugador]['puntos']) | |
print("Rebotes: ", equipo[jugador]['rebotes']) | |
def printTodo(equipo): | |
for jug in equipo: | |
printJugador(dicdic, jug) | |
print('-----------') | |
def enCancha(equipo, pos): | |
l = [] | |
for jug in equipo: | |
if equipo[jug]['posición'] == pos: | |
l.append(jug) | |
return l | |
# ------------------------------- | |
dicdic = leeFichEquipoBaloncesto("equipoBaloncesto.txt") | |
listaConMasRebotes = masRebotes(dicdic) | |
print(listaConMasRebotes) | |
lisJugMasPuntos = masPuntos(dicdic) | |
print(lisJugMasPuntos) | |
print(mediaPuntos(dicdic)) | |
print(jugadorDeDorsal(dicdic, 5)) | |
printJugador(dicdic, 'Berni Rodriguez') | |
printTodo(dicdic) | |
print("Pivot's:", enCancha(dicdic, 'Pivot')) | |
# Berni Rodriguez, 5, E, 5.2, 1.7 | |
# Luka Zoric, 21, P, 11.2, 4.8 | |
# Jorge Garbajosa, 15, L, 7, 3.3 | |
# Nedzad Sinanovic, 22, P, 4.2, 3.1 | |
# Joel Freeland, 19, P, 13.9, 7.1 | |
# Hrvoje Peric, 10, A, 7.7, 3 | |
# Gerald Fitch, 4, E, 10.9, 3.8 | |
# EJ Rowland, 6, B, 6, 2.5 | |
# Kristaps Valters, 9, B, 10.8, 1.9 | |
# Saul Blanco, 34, A, 2.2, 1.2 | |
# Tremmell Darden, 12, A, 9.1, 3.6 | |
# Alex Abrines, 16, A, 0.6, 0.4 | |
# Mark Payne, 20, A, 5.6, 1.9 | |
# Augusto Lima, 7, L, 2.7, 3.0 | |
# Pepe Pozas, 14, A, 1.0, 1.0 | |
# Ognjen Kuzmic, 7, A, 0.0, 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment