Skip to content

Commit

Permalink
explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
procho committed Oct 19, 2019
1 parent a6411d9 commit 9353180
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pfb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2427,10 +2427,12 @@ print(nt_count)
If you want to print the contents of a dictionary, you should sort the keys then iterate over the keys with a for loop. Why do you want to sort the keys?

```python
for gene_key in sorted(genes):
for gene_key in sorted(genes): # python allows you to use this shortcut in a for loop
# you don't have to write genes.keys() in a for loop
# to iterate over the keys
print(gene_key, '=>' , genes[gene_key])
```
> This will print the same order of keys every time you run your script.
> This will print keys in the same order every time you run your script. Dictionaries are unordered, so without sorting, you'll get a different order every time you run the script, which could be confusing.

#### Dictionary Functions
Expand Down

0 comments on commit 9353180

Please sign in to comment.