Chalarangelo / 30-seconds-of-python

Short Python code snippets for all your development needs
https://www.30secondsofcode.org/python/p/1
Creative Commons Attribution 4.0 International
8.83k stars 1.26k forks source link

Update sample.md #181

Closed callamd closed 4 years ago

callamd commented 4 years ago

Pythonic import + choice method

Description

Resolves #(issue number)

What does your PR belong to?

Types of changes

Checklist:

callamd commented 4 years ago

@Chalarangelo why do we import things without their namespace? I thought it was generally accepted that in production codebases something like namespace.method is preferable to method.

I can update this PR to add a description for random.choice; I do think it is a more pythonic way of retrieving a random element from a list.

Thanks!

Chalarangelo commented 4 years ago

Things are imported like this across the board for consistency and brevity. Using random.choice() seems like a good idea, you can update the description if you like.

callamd commented 4 years ago

If you want the code to be character by character as you've suggested you can do it.