To create a dictionary that contains the fourth power of integers up to n, you can use a dictionary comprehension like this:
main.py77 chars4 lines
Output:
main.py84 chars2 lines
The range(1, n+1)
creates a sequence of integers from 1 to n (inclusive). The i**4
calculates the fourth power of each integer. Finally, the dictionary comprehension creates a new dictionary with keys as the input integers and values as the corresponding fourth power of that integer.
gistlibby LogSnag