Vikram Chiluka

Literals in Python

Literals in Python

Literals are a type of notation used in source code to represent a fixed value. They can also be defined as raw values or data that are given in variables or constants.

This article will teach you about the various types of literals in Python.

Python Literals

In Python, there are various types of literals. As an example,

1)Numeric Literals

In Python, numerical literals represent numbers and can be of the following types:

  • Integer Literal:
    • Both positive and negative numbers, including 0 are allowed. There must be no fractional parts.
    • Ex : 100 , -200 , 300 etc.
  • Float Literal:
    • These are real numbers with integer and fractional components.
    • Ex : 45.5 , 28.4 etc.
  • Binary Literal:
    • Numbers are represented in binary form.
    • For example, 1010 is binary literal for 10
  • Octal Literal:
    • Numbers are represented in octal form.
  • Hexadecimal Literal:
    • Numbers are represented in Hexadecimal form.
  • Complex Literal:
    • Complex numbers are represented by this type.
    • For example 6+ 3i ,4+2i etc.

2)Boolean Literals

In Python, only True and False are Boolean literals.

3)String literals

A string literal is made by enclosing a text(a set of characters) in single(”), double(“”), or triple(“”) quotes. We can write multi-line strings or show in the desired way by using triple quotes.

# string literals in python
# single quote representation of string
string1 = 'BTechGeeks'

# double quotes representation of string
string2 = "BTechGeeks"

# multiline representation of string
string3 = '''BTech
        Geeks
            Platform'''

print('single quote string:', string1)
print('double quote string:', string2)
print('multiline string :', string3)

Output:

single quote string: BTechGeeks
double quote string: BTechGeeks
multiline string : BTech
		Geeks
			Platform

4)Special literals

There is one special literal in Python (None). A null variable is described by the word ‘none.’ When ‘None’ is contrasted to something other than another ‘None,’ it returns false.

# special literal none
special = None
print(special)

Output:

None

5)Escape characters

  • \ :  Newline continuation
  • \\ : Display a single \
  • \’ : Display a single quote
  • \” : Display a double quote
  • \b : Backspace
  • \n : New Line
  • \t : Horizontal Tab
  • \v : Vertical Tab
  • \r : Enter

Related Programs:

How to Create Multi Line String Objects

How to Create Multi Line String Objects in Python ?

A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0’s and 1’s internally.

In this article we are going to discuss how to create multi line string objects in python.

Create and Convert Multi Line String Objects in Python

Creating multi line string objects:

Converting multi line string objects to single line objects:

Method #1:Using triple quotes

We can assign the multi-line string to a string variable by enclosing it in triple quotes, i.e. either <> or It will be saved in the same multi-line format as before.

Below is the implementation:

# creating multi line string
multistring = '''Hello this is
               BTechGeeks python
               new learning platform'''
# printing the string
print(multistring)

Output:

Hello this is
               BTechGeeks python
               new learning platform

Creating single line string from multi line string

Method #1:Using brackets

If we want to create a string object from multiple long lines but keep them all in a single line, we should use brackets.

Below is the implementation:

# creating single line string from multi line string
singlestring = ("Hello this is "
                "BTechGeeks python "
                "new learning platform")
# printing the string
print(singlestring)

Output:

Hello this is BTechGeeks python new learning platform

Method #2:Using Escape( \ ) symbol

We can also use the escape character to create a single line string object from a long string of multiple lines.

Below is the implementation:

# creating single line string from multi line string
singlestring = "Hello this is "\
    "BTechGeeks python "\
    "new learning platform"
# printing the string
print(singlestring)

Output:

Hello this is BTechGeeks python new learning platform

Method #3:Using join()

We can also make a single line string object by joining several lines together.

Below is the implementation:

# creating single line string from multi line string
singlestring = ''.join(
    ("Hello this is "
     "BTechGeeks python "
     "new learning platform"))
# printing the string
print(singlestring)

Output:

Hello this is BTechGeeks python new learning platform

Related Programs:

Convert Dictionary to List of Tuples Pairs

Python: Convert Dictionary to List of Tuples/ Pairs

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

Examples:

Input:

dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}

Output:

[('This', 100), ('is', 200), ('BTechGeeks', 300)]

Convert Dictionary to List of Tuples/ Pairs

There are several ways to convert dictionary to list of tuples/pairs some of them are:

Method #1:Using zip() function

The zip function combines the parameters passed to it. So we pass the dictionary’s keys and values as parameters to the zip function, and the result is passed to a list function. The key-value pair is converted into a list of tuples.

Below is the implementation:

# given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting dictionary to list of tuples
listtuple = list(zip(dictionary.keys(), dictionary.values()))
# print list of tuples
print(listtuple)

Output:

[('This', 100), ('is', 200), ('BTechGeeks', 300)]

Method #2:Using items()

The dictionary class in Python includes the items() function, which returns an iterable sequence (dict items) of all key-value pairs in the dictionary. This retuned sequence is a representation of the dictionary’s actual key-value pairs. To get a list of tuples, we can pass this iterable sequence to the list() function.

Below is the implementation:

# given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting dictionary to list of tuples
listtuple = list(dictionary.items())
# print list of tuples
print(listtuple)

Output:

[('This', 100), ('is', 200), ('BTechGeeks', 300)]

Method #3:Using List Comprehension

dict.items() returns an iterable sequence of all dictionary key-value pairs. We may use a list comprehension to iterate over this sequence and create a list of tuples. The ith tuple in this list of tuples represents the ith dictionary key-value pair.

Below is the implementation:

# given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting dictionary to list of tuples using list comprehension
listtuple = [(key, value) for key, value in dictionary.items()]
# print list of tuples
print(listtuple)

Output:

[('This', 100), ('is', 200), ('BTechGeeks', 300)]

Method #4:Using for loop and append() functions

We can start with an empty list of tuples and then use a for loop to iterate over all key-value pairs in the dictionary, adding each key-value pair to the list one by one.

Below is the implementation:

# given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# creating empty list
listtuple = []
# using for loop to traverse the dictionary
for key in dictionary:
    # append key and value to list as a tuple
    listtuple.append((key, dictionary[key]))

# print list of tuples
print(listtuple)

Output:

[('This', 100), ('is', 200), ('BTechGeeks', 300)]

Related Programs:

String isupper() Method

Python String isupper() Method

A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0’s and 1’s internally.

In this article we are going to discuss about isupper() method

String isupper() method in Python

1)isupper() method

If all of the characters are in upper case, the isupper() method returns True otherwise, it returns False.

Only alphabet characters are checked, not numbers, symbols, or spaces.

Syntax:

given_string.isupper()

Parameters:

No parameters are passed

Return:

If all cased characters in the string are uppercase and there is at least one cased character, this method returns true; otherwise, it returns false.

Examples:

2)Checking if given string is an uppercase or not

Using the isuuper() function, we can determine whether a string is uppercase or lowercase. If all of the string characters are upper case, the function isupper() returns True.

Below is the implementation:

# given string
string = "BTECHGEEKS"
# determining whether the given string is uppercase
if(string.isupper()):
    print("Given string is in uppercase")
else:
    print("Given string is not in uppercase")

Output:

Given string is in uppercase

EX-2)

# given string
string = "Btechgeeks"
# determining whether the given string is uppercase
if(string.isupper()):
    print("Given string is in uppercase")
else:
    print("Given string is not in uppercase")

Output:

Given string is not in uppercase

3)Checking if given number string is an uppercase or not

Assume we have a string that only contains numbers. Let’s use isupper to see if this string is uppercase or not ().

Below is the implementation:

# given string
string = "28112001"
# determining whether the given string is uppercase
if(string.isupper()):
    print("Given string is in uppercase")
else:
    print("Given string is not in uppercase")

Output:

Given string is not in uppercase

4)Checking if given string containing letters and numbers an uppercase or not

Assume we have a string that contains numbers and uppercase letters. Let’s use isupper to see if this string is uppercase or not ()

Below is the implementation:

# given string
string = "BTECH-28112001"
# determining whether the given string is uppercase
if(string.isupper()):
    print("Given string is in uppercase")
else:
    print("Given string is not in uppercase")

Output:

Given string is in uppercase

Explanation:

As string contains one or more upper case characters but no lower case characters. As a result, isupper() returned True.

5)Checking if given character is in uppercase or not

Individual characters have no data type in Python. A python string object can also be a single character. As a result, we can use the isupper() method to determine whether a character is upper case or not.

Below is the implementation:

# given string
string = "S"
# determining whether the given string is uppercase
if(string.isupper()):
    print("Given char is in uppercase")
else:
    print("Given char is not in uppercase")

Output:

Given char is in uppercase

 
Related Programs:

Print Specific Key-Value Pairs of Dictionary

Python: Print Specific Key-Value Pairs of Dictionary

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

Given a dictionary, the task is to print specific key-value pairs of the Dictionary.

Display Specific Key-Value Pairs of Dictionary

Indexing:

Dictionary’s items() function returns an iterable sequence of dictionary key-value pairs, i.e. dict items. However, this is a view-only sequence, and we cannot use indexing on it. So, if we want to use indexing to select items from a dictionary, we must first create a list of pairs from this sequence.

We can convert dictionary items to list using list() function

Below is the implementation:

# Given dictionary
dictionary = {'this': 200, 'is': 100, 'BTechGeeks': 300}
# convert the dictionary to list using items()
dictlist = list(dictionary.items())
# using indexing we can print the first key value pair of dictionary
print("1st key value pair :", dictlist[0])

Output:

1st key value pair : ('this', 200)

We can print last key value pair of dictionary using negative indexing(-1) or using length function of list.

Below is the implementation:

# Given dictionary
dictionary = {'this': 200, 'is': 100, 'BTechGeeks': 300}
# convert the dictionary to list using items()
dictlist = list(dictionary.items())
# using indexing we can print the last key value pair of dictionary
print("last key value pair :", dictlist[-1])

Output:

last key value pair : ('BTechGeeks', 300)

We can print nth key-value pair using indexing

Below is the implementation:

# Given dictionary
dictionary = {'this': 200, 'is': 100, 'BTechGeeks': 300}
# given n
n = 2
# convert the dictionary to list using items()
dictlist = list(dictionary.items())
# using indexing we can print the nth key value pair of dictionary
print("nth key value pair :", dictlist[n-1])

Output:

nth key value pair : ('is', 100)

4)Printing specific key-value pairs based on given conditions

To print specific dictionary items that satisfy a condition, we can iterate over all dictionary pairs and check the condition for each pair. If the condition returns True, then print the pair otherwise, skip it.

Let us print all the key-value pairs whose value is greater than 100

Below is the implementation:

# Given dictionary
dictionary = {'this': 200, 'is': 100, 'BTechGeeks': 300}
# convert the dictionary to list using items()
dictlist = list(dictionary.items())
# Traverse the dictionary
for key, value in dictionary.items():
    # if the value is greater than 100 then print it
    if(value > 100):
        print(key, value)

Output:

this 200
BTechGeeks 300

Related Programs:

Remove Elements from a List while Iterating

Python: Remove Elements from a List while Iterating

A collection is an ordered list of values. There could be various types of values. A list is a mutable container. This means that existing ones can be added to, deleted from, or changed.

The Python list represents the mathematical concept of a finite sequence. List values are referred to as list items or list elements. The same value may appear multiple times in a list. Each event is regarded as a distinct element.

Example:

Input:

givenlist = ["hello", "this", "is", "this", "BTechGeeks", "this", "python"]

Output:

['hello', 'is', 'BTechGeeks', 'python']

Delete Elements from a List while Iterating

There are several ways to remove elements from the list while iterating some of them are:

Method #1:Using for in loop

To accomplish this, we must first make a copy of the list, and then iterate over that copied list. Then, for each element, we’ll decide whether or not to delete it. If so, use the remove() function to remove that element from the original list.

Below is the implementation:

# given list
givenlist = ["hello", "this", "is", "this", "BTechGeeks", "this", "python"]
# given element which should be deleted
key = "this"
for element in list(givenlist):
    # checking if the element is equal to given key
    if(element == key):
        # using remove to remove element from list
        givenlist.remove(element)
# print the list
print(givenlist)

Output:

['hello', 'is', 'BTechGeeks', 'python']

Method #2:Using List Comprehension

Using list comprehension, we can iterate over the list and choose which elements to keep in the new list. The new list can then be assigned to the same reference variable that was part of the original list.

Below is the implementation:

# given list
givenlist = ["hello", "this", "is", "this", "BTechGeeks", "this", "python"]
# given element which should be deleted
key = "this"
# using list comprehension to remove given element from the list
givenlist = [element for element in givenlist if element != key]
# print the list
print(givenlist)

Output:

['hello', 'is', 'BTechGeeks', 'python']

Method #3:Using filter() function

The Filter() function takes two arguments,

The first is a Lambda function, which can be any function.
The second list is the one from which we want to remove elements.
It iterates through all of the list’s elements, applying the given function to each one. It returns the elements for which the given function returns True during iteration. So we can use the filter() function to iteratively filter elements from a list.

Below is the implementation:

# given list
givenlist = ["hello", "this", "is", "this", "BTechGeeks", "this", "python"]
# given element which should be deleted
key = "this"
# using filter() function to remove given element from the list
givenlist = list(filter(lambda element: element != key, givenlist))
# print the list
print(givenlist)

Output:

['hello', 'is', 'BTechGeeks', 'python']

Related Programs:

Create a List of all the Keys in the Dictionary

Python : How to Create a List of all the Keys in the Dictionary ?

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

Examples:

Input:

dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}

Output:

['This', 'is', 'BTechGeeks']

Create a List of all keys of a Dictionary

There are several ways to create a list of all keys of a dictionary some of them are:

Method #1:Using keys() +list() function

The dictionary class in Python has a member function called dict.keys ()

It returns a view object or an iterator that iterates through the list of all keys in the dictionary. This object can be used for iteration or to create a new list.

Below is the implementation:

# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting the keys of dictionary using keys() +list() function
keyslist = list(dictionary.keys())
# print the list of keys
print(keyslist)

Output:

['This', 'is', 'BTechGeeks']

Method #2 :Using unpacking (*args)

Unpacking with * works with any iterable object, and because dictionaries return their keys when iterated through, it is simple to create a list by using it within a list literal.

Below is the implementation:

# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting the keys of dictionary using args(*) function
keyslist = [*dictionary]
# print the list of keys
print(keyslist)

Output:

['This', 'is', 'BTechGeeks']

Method #3 :Using List Comprehension

We can convert to list using list comprehension in a single line.

Below is the implementation:

# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# converting the keys of dictionary using list comprehension
keyslist = [key for key in dictionary]
# print the list of keys
print(keyslist)

Output:

['This', 'is', 'BTechGeeks']

Related Programs:

How to Iterate over Nested Dictionary -Dict of Dicts

Python: How to Iterate over Nested Dictionary -Dict of Dicts

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

To an infinite depth, a dictionary may include another dictionary, which can contain dictionaries, and so on. This is referred to as a nested dictionary.

Nested dictionaries are one among several ways during which structured information is represented (similar to records or structures in other languages).

Examples:

Input:

nesteddict = {
'hello': {'www': 100, 'yyy': 'Helloworld'},
'this': {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},
'BTechGeeks': {'PLACE': 'HYDERABAD', 'PINCODE': 500000,
'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},

Output:

('hello', 'www', 100)
('hello', 'yyy', 'Helloworld')
('this', 'www', 'vikram')
('this', 'age', 20)
('this', 'DOB', 'FEB')
('BTechGeeks', 'PLACE', 'HYDERABAD')
('BTechGeeks', 'PINCODE', 500000)
('BTechGeeks', 'PYTHON', 'FUNCTIONS', 'Built in')
('BTechGeeks', 'PYTHON', 'year', 1999)

Traverse over Nested Dictionary

To get an iterable sequence of all key-value pairs in a normal dictionary, simply call the dictionary’s items() function. A value in a nested dictionary, on the other hand, can be another dictionary object. To accomplish this, we must call the items() function again on such values to obtain another iterable sequence of pairs and then search for dict objects within those pairs as well. Using recursion, we can accomplish all of this in a straightforward manner.

We wrote a function that takes a dictionary as an argument and returns all key-value pairs contained within it. Internal / nested dictionary values were included. It returns a tuple containing all keys for that value in hierarchy for nested structures.

Below is the implementation:

# function which print all the values of nested dictionary
def printNested(nesteddict):
    # Traverse the dictionary
    for key, value in nesteddict.items():
        # If the value is of the dictionary type, then print
        # all of the keys and values within the nested dictionary.
        if isinstance(value, dict):
            for pair in printNested(value):
                yield (key, *pair)
        else:
            yield(key, value)


# given nested_dictionary
nesteddict = {
    'hello':    {'www': 100, 'yyy': 'Helloworld'},
    'this':    {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},
    'BTechGeeks':    {'PLACE': 'HYDERABAD', 'PINCODE': 500000,
                      'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},
}
# passing nested dictionary to printNested Function using loop
for pair in printNested(nesteddict):
    print(pair)

Output:

('hello', 'www', 100)
('hello', 'yyy', 'Helloworld')
('this', 'www', 'vikram')
('this', 'age', 20)
('this', 'DOB', 'FEB')
('BTechGeeks', 'PLACE', 'HYDERABAD')
('BTechGeeks', 'PINCODE', 500000)
('BTechGeeks', 'PYTHON', 'FUNCTIONS', 'Built in')
('BTechGeeks', 'PYTHON', 'year', 1999)

Working of the above function:

We iterated over all the values in a dictionary of dictionaries using the function nested dict pair iterator() and printed each pair, including the parent keys.

We iterated over all the key-value pairs of a given dictionary object within the function, and for each value object in the pair, we checked whether the value is of dict type or not. If not, it just returns the pair, but if value is a dict, it calls itself again with the dict value object as an argument and returns all of its key-value pairs. The process is repeated until all of the internal dictionary objects have not been covered. This is how a dictionary of dictionaries’ key-value pairs are generated.
Related Programs:

Print all Key-Value Pairs of a Dictionary

Python: Print all Key-Value Pairs of a Dictionary

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

Given a dictionary, the task is to print all key and values of the dictionary.

Examples:

Input:

dictionary = {"this": 100, "is": 200, "BTechGeeks": 300}

Output:

This 100
is 200
BTechGeeks 300

Display all Key-value pairs of a Dictionary

There are several ways to traverse the dictionary some of them are:

Method #1: Using for loop (iterating over keys only)

To iterate over all keys in a dictionary, a dictionary object can also be used as an iterable object. As a result, we can use for loop on a dictionary with ease. It loops through all of the keys in the dictionary using for in the dictionary. We will print the value associated with each key.

Below is the implementation:

# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# Using for loop to traverse the dictionary
for key in dictionary:
    # Getting value at key
    value = dictionary[key]
    # printing values and keys
    print(key, value)

Output:

This 100
is 200
BTechGeeks 300

Method #2:Using for loop and items()

The items() function of the dictionary class returns an iterable sequence of all key-value pairs within the dictionary. We can use a for loop to iterate through this list of pairs and print them one by one.

Below is the implementation:

# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}

# Printing all key-value pairs
for key, value in dictionary.items():
    print(key, value)

Output:

This 100
is 200
BTechGeeks 300

Method #3:Using List Comprehension

Since the items() function of a dictionary returns an iterable sequence of key-value pairs, we may use this list comprehension to iterate over all diction pairs.

Below is the implementation:

# Given dictionary 
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300} 
# Using list comprehension 
[print(key, value) for key, value in dictionary.items()]

Output:

This 100
is 200
BTechGeeks 300
# Given dictionary
dictionary = {'This': 100, 'is': 200, 'BTechGeeks': 300}
# Using items and converting dictionary to list
dictlist = list(dictionary.items())
# traversing in reversed of this list
for key, value in reversed(dictlist):
    print(key, value)

Output:

BTechGeeks 300
is 200
This 100

Related Programs:

IterateLoop over all Nested Dictionary values

Python: Iterate/Loop over all Nested Dictionary values

Dictionaries are Python’s implementation of an associative list, which may be a arrangement . A dictionary may be a collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.

To an infinite depth, a dictionary may include another dictionary, which can contain dictionaries, and so on. This is referred to as a nested dictionary.

Nested dictionaries are one among several ways during which structured information is represented (similar to records or structures in other languages).

Examples:

Input:

nesteddict = {
'hello': {'www': 100, 'yyy': 'Helloworld'},
'this': {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},
'BTechGeeks': {'PLACE': 'HYDERABAD', 'PINCODE': 500000,
'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},
}

Output:

100
Helloworld
vikram
20
FEB
HYDERABAD
500000
Built in
1999

Traverse over all Nested Dictionary

1)Traverse the values of nested Dictionary

We can only call the values() function of a dictionary for a normal dictionary to get an iterable sequence of values. However, a value can be another dictionary object in a nested dictionary. To do this, we need to call the values() function again and get a new iterative sequence of values and search for dictation objects in those values. This is possible with recurrence in a simple way.

To print all of the values in this dictionary, we wrote a function that will recursively go through the nested dictionary and print all of the values.

Below is the implementation:

# function which print all the values of nested dictionary


def printNested(nesteddict):
    # Traverse the dictionary
    for key, value in nesteddict.items():
        # If the value is of the dictionary type, then print
        # all of the values within the nested dictionary.
        if isinstance(value, dict):
            printNested(value)
        else:
            print(value)


# given nested_dictionary
nesteddict = {
    'hello':    {'www': 100, 'yyy': 'Helloworld'},
    'this':    {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},
    'BTechGeeks':    {'PLACE': 'HYDERABAD', 'PINCODE': 500000,
                      'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},
}
# passing nested dictionary to printNested Function
printNested(nesteddict)

Output:

100
Helloworld
vikram
20
FEB
HYDERABAD
500000
Built in
1999

2)Convert all nested dictionary values to list

We can convert nested dictionary values to list by taking an empty list and appending all values to list as shown below.

Below is the implementation:

# function which print all the values of nested dictionary


def printNested(newlist, nesteddict):
    # Traverse the dictionary
    for key, value in nesteddict.items():
        # If the value is of the dictionary type, then print
        # all of the values within the nested dictionary.
        if isinstance(value, dict):
            printNested(newlist, value)
        else:
            newlist.append(value)
    return newlist


# given nested_dictionary
nesteddict = {
    'hello':    {'www': 100, 'yyy': 'Helloworld'},
    'this':    {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},
    'BTechGeeks':    {'PLACE': 'HYDERABAD', 'PINCODE': 500000,
                      'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},
}
newlist = []
# passing nested dictionary to printNested Function
print(printNested(newlist, nesteddict))

Output:

[100, 'Helloworld', 'vikram', 20, 'FEB', 'HYDERABAD', 500000, 'Built in', 1999]

Related Programs: