You are currently viewing what is dict and list comprehensions in python and how to use them
Key point about Dict comprehension

what is dict and list comprehensions in python and how to use them

Spread the love
Key point about Dict comprehension
Key point about Dict comprehension

Key point about Dict comprehension :

1) Dict is a Dictionary which is used in python.

 2)Dictionary is used to store elements.

 3)Dict is an unordered and mutable python container,which stores mapping of unique keys to values.

 4)Dictionaries are written with curly brackets({}). Key value pairs are separated by comma(,) , a colon(:). It separates each key value from its value.

 5)Dict is a kind of Hash Table.

6)Number and strings are used in dict.

7)In dict duplicate values are not allowed.

8)Dictionary comprehension used to convert one dictionary to another dictionary.

9)Dict is a powerful concept and used for lambda and loops functions.

Also see : Database in python

Example on Dict comprehension :

my_dict={‘name’ : ‘om’, ‘age’ : 17} 
print(my_dict[‘name’])
print(my_dict.get(‘age’))
print(my_dict[‘address’])
Output:-
      Om
      17

Key point about List Comprehension :

  1. List is used for creating new list from other iterables.
  2. List comprehension returns list, it consist brackets which contains expressions. This expressions executed for element along with for loop to iterate over each element.
  3. Basic Syntax Of List- new_list =[expression
    for_loop_one_or_more conditions]
  4. It offers a short syntax when to create a new list which depends upon the values of an existing lists.
  5. It is more compact and faster than the normal functions and loops for creating list.
  6. There are three elements in every list comprehensions
    a)Expression- It is the member of itself.
    b)Member-It is the object or value in the list or iterable
    c)Iterable- It is a list,set,sequence,generator,or any other object that can returns its elements one at a time.

Also see : Decorator in python

Summary :

In this article we saw what is dict and list comprehensions in python and how to use them. so about this section you have any query then free to ask me

Name of Intern who share this Task :

Prafulla Rajendra Aher

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply