Skip to content

Commit 9690e76

Browse files
author
root
committed
Dic
1 parent 7a28e24 commit 9690e76

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Dictionanry_Demo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#It is simmilar to lists excepts that it aceepts item as key value pair
2+
#user = ['mahesh','35','Devops Engoneer','US']
3+
user = {
4+
"username":"mahesh",
5+
"age":"35",
6+
"job":"Devops Engineer",
7+
"country":"US"
8+
}
9+
10+
print ("The Username is",user["username"],", he is",user["age"],"years old","he works as",user["job"],"and lives in",user["country"] )
11+

List_Comprehension.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Your security team said every username contains 1 didgit
2+
# for example above user list is not valid we have to loop through the list and digit for the same
3+
num = "123"
4+
users =["user1","user2","user3","user4"]
5+
#traditional way
6+
for i in range(0,len(users)):
7+
users[i]= users[i] + num
8+
9+
print (users)
10+
11+
#Using Python_List Comprehension
12+
users = [u+num for u in users]
13+
print (users)

loop_through_Dic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
langs={
2+
"en":"English",
3+
"es":"Spanish",
4+
"ar":"Arabic",
5+
"it":"Italian"
6+
}
7+
8+
for key,value in langs.items():
9+
print(key,":",value)
10+

0 commit comments

Comments
 (0)