Example #1
0
import babynames

print("The Fantastic Four!")
print("-" * 19)

names = {
    name: sum(babynames.get_frequency(name).values())
    for name in ["Reed", "Susan", "Ben", "Johnny"]
}

for name, count in names.items():
    print(f"{name:>7}: {count:>9,}")

print(f"\n{max(names, key=names.get)} is the most popular!")
Example #2
0
            names = str(sys.argv[i+1])
            namesList = names.split(",")          
            i+=1
        else:
            printUsage()
            sys.exit(1)
    elif (sys.argv[i] == "-file"):
        if (i+1 < len(sys.argv)) and (sys.argv[i+1] != "-names") and (sys.argv[i+1] != ""):
            file = str(sys.argv[i+1])
            i+=1
        else:
            printUsage()
            sys.exit(1)
    i+=1
    
names = {name: sum(babynames.get_frequency(name).values()) for name in namesList}
babynames.plt.style.use(['dark_background'])

for name, count in names.items():
    print(f"{name:>7}: {count:>9,}")

print(f"\n{max(names, key=names.get)} is the most popular!")

babynames.plt.figure()
for name in namesList:
    totals = babynames.get_frequency(name)
    babynames.plt.plot([*totals.keys()], [*totals.values()], label=name)
babynames.plt.legend()

if file == "example":
   babynames.plt.show()