
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Append Dictionary Keys and Values (In order ) in dictionary using Python
When it is required to append the keys and values of a dictionary in order, the ‘list’ method can be used. Along with this, the ‘.keys’ and ‘.values’ method can be used access the specific keys and values of the dictionary.
Below is a demonstration of the same −
Example
my_dict = {"January" : 1, "Feb" : 2, "March" : 3, 'April':4, 'May' : 5, 'June' :6} print("The dictionary is : ") print(my_dict) my_result = list(my_dict.keys()) + list(my_dict.values()) print("The ordered key and value are : ") print(my_result)
Output
The dictionary is : {'January': 1, 'Feb': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6} The ordered key and value are : ['January', 'Feb', 'March', 'April', 'May', 'June', 1, 2, 3, 4, 5, 6]
Explanation
A dictionary is defined, and is displayed on the console.
The keys of the dictionary are accessed using the ‘keys’ method and the values of dictionary are accessed using ‘values’ method.
It is converted to a list and is concatenated using the ‘+’ operator.
This is displayed on the console as the output.
- Related Articles
- Keys associated with Values in Dictionary in Python
- Find keys with duplicate values in dictionary in Python
- How to Common keys in list and dictionary using Python
- Python – Limit the values to keys in a Dictionary List
- Properties of Dictionary Keys in Python
- How to convert Python dictionary keys/values to lowercase?
- How to insert new keys/values into Python dictionary?
- Python - Combine two dictionary adding values for common keys
- How to create Python dictionary from list of keys and values?
- Python Extract specific keys from dictionary?
- Python - Cumulative Mean of Dictionary keys
- Get dictionary keys as a list in Python
- Why must dictionary keys be immutable in Python?
- How does Python dictionary keys() Method work?
- Python dictionary with keys having multiple inputs

Advertisements