Python Workout
Published in

Python Workout

Workout #27: Password Generator

In this exercise, we’re going to create a password-generation function. Actually, we’re going to create a factory for password-generation functions. That is, I might need to generate a large number of passwords, all of which use the same set of characters. (You know how it is. Some applications require a mix of capital letters, lowercase letters, numbers, and symbols; whereas others require that you only use letters; and still others allow both letters and digits.) You’ll thus call the function create_password _generator with a string. That string will return a function, which itself takes an integer argument. Calling this function will return a password of the specified length, using the string from which it was created; for example

alpha_password = create_password_generator('abcdef')
symbol_password = create_password_generator('!@#$%')
print(alpha_password(5)) # efeaa
print(alpha_password(10)) # cacdacbada
print(symbol_password(5)) # %#@%@
print(symbol_password(10)) # @!%%$%$%%#

TRY IT YOURSELF

ANSWER

https://colab.research.google.com/drive/13AHympDmX53ItCXP_TBnwWHoUxyywtkH?usp=sharing

--

--

--

Python problems and solutions, follows the text “Python Workout” by Reuven M. Lerner.

Recommended from Medium

How to increase Maximum upload file size in WordPress

A Dachshund in Software Engineering: A Short Story

RDS, Upgrading Postgres Versions

Explaining the SettingWithCopyWarning in pandas

Simple Steps to Get Started with Youtube API — 10 min

The Top 10 Python Packages for Computer Vision

kubernetes/kubeflow install

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abish Pius

Abish Pius

Data Science Professional who teaches with unflashy, simple to understand python code.

More from Medium

OBJECT RELATIONAL MAPPING

Mongo DB Complete Cheat Sheet

How to get into coding with Pyton

02 of 100 Days Of Code

Quick sort algorithm visualization from enjoyalgorithms.com