Find max or min in Python dictionary
Suppose that mydict is a dictionary defined by
1 | mydict = {'a': 2, 'c': 5, 'b': 1, 'd': 4} |
How to find the key for the max or min value in the items?
To leave furtively and stealthily.
Posts tagged ‘Python’
Suppose that mydict is a dictionary defined by
1 | mydict = {'a': 2, 'c': 5, 'b': 1, 'd': 4} |
How to find the key for the max or min value in the items?
Suppose that mydict is a dictionary defined by
1 | mydict = {'a': 2, 'c': 5, 'b': 1, 'd': 4} |
Remember that dictionary has no function sort, since it is unordered, not like a list, or tuple.
However, the key function, introduced in version 2.4, is helpful in sorting a dictionary.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …
Mathematically, we write it as:
F(n) = F(n) + F(n-1)
This can easily be done in Python, using generators.
Komodo Edit is a good editor for many programming language. However, since it is free as compared to its brother Komodo IDE, there is lack of debugging function.
Komodo Edit is a good free editor for Python development. However, there is no debugging feature in Komodo Edit. Therefore, it is a cumbersome process to execute Python scripts. Fortunately, there is a feature called Run command to satisfy this job.
To make use of the Run command feature to execute Python code, you can follow these steps:
Now, you can easily execute the Python script by pressing “F5″, or by double clicking the “Run Python file” in your toolbox pane, which is usually located at the right. The output will be displayed in the Command output pane at the bottom.
For more information on the “Run Command”:
Problem #1 of Project Euler
Add all the natural numbers below 1000 that are multiples of 3 or 5.
Continue reading ‘Add all the natural numbers below 1000 that are multiples of 3 or 5’ »
This Python script was written for a friend in Australia, for part of his Ph.D project. The script will parse the Apache server log into sqlite3 database.
Continue reading ‘Python: Parse Apache log to sqlite database’ »
Suppose that we have a conditional statement:
In Python, we can write it in three ways:
Continue reading ‘Python: Conditional Statement with lambda’ »
This tutorial will show how to give a Python list an initial value.
To initialize list myTuple values to 0, with 10 items:
Continue reading ‘Python: Initialize list and tuple values’ »
py2exe is a Python package that can convert Python scripts into executable Windows programs. This is an example of py2exe setup file.