Python Tutorial - 11. Dictionaries and Tuples

preview_player
Показать описание
In this python tutorial, we will understand the concept of “dictionaries and tuples”. We will understand what are dictionaries, “order in a dictionary”, how to access dictionary element, what is “tuples” and the difference between “list and tuple”.

Topics that are covered in this Python Video:
0:00 Introduction
0:20 What is the dictionary
1:42 Access dictionary element
3:03 Order in the dictionary
3:26 delete from the dictionary
5:22 in operator in the dictionary
6:40 tuples
7:42 Difference between list and tuple
9:14 Tuples are immutable

Next Video:

Рекомендации по теме
Комментарии
Автор

I've studied for almost 10 hours today, this music was the greatest thing ever

malcolmhollett
Автор

at 5.23 you are printing key instead of k, so it is showing the value of previously stored key...

ashuupdate
Автор

Your tutorial is awesome...Could you plz. tell me, how the "for k, v in d.items(): print(key, v) " is working ?

prabavathim
Автор

dic = dict()



n=input("How many inpurt do you need ?")
for i in range(0, n):
a = raw_input("Enter Key")
b = input("Enter value")
dic[a] = b

for k, v in dic.items():
print("KEY :", k, "Value ", v)

print(dic)

for k in dic:
print("KEYS : ", k, "Values :", dic[k] )

shabbirhussain
Автор

can you made video tutorial on django with trail full website

Mohitraj-kqjn
Автор

wow man...made my life..
Nice one Subscribed...Keep'em comin....

ShinyArjunSingh
Автор

Solution For Given Exercise:
name1=input("Enter Your First Name")
name2=input("Enter Your Second Name")
name3=input("Enter Your Third Name")
name4=input("Enter Your Fourth Name")
p=int(input("Enter Age Of name1"))
q=int(input("Enter Age Of name2"))
r=int(input("Enter Age Of name3"))
s=int(input("Enter Age Of name4"))
d={name1:p, name2:q, name3:r, name4:s}
print("Whose Age You Want To Know")
key=input("Enter Here")
if key in d :
print("Age:", d[key])
else :
print("Enter A Valid Input")
print(d)

KishanKumar-xfcr
Автор

Hi, I am not sure about my code..
Please check this answer and guide.

dict = {}
n = int(input("Enter total numbers of records : "))
for i in range(n):
i = input("Enter Name : ")
j = input("Enter Age : ")
dict[i] = j
search_name = input("Enter name for search : ")
if search_name in dict:
print(dict[search_name])
else:
print("Not Found")

umarless
Автор

Hi:
First of all your tutorial is very awesome and easy to grasp. Thank you for sharing the same.
i have a doubt with respect to dictionary
suppose i have a dictionary . d = {True: 'yes', 1: 'no', 1.0: 'maybe'}. while accessing the key of d[True] the value is shown as 'maybe', also if i access d[1] still i get the value as 'maybe'. Can you please help out for the same.
Thanks !

punitkanojia.
Автор

For 2nd exercise using dictionary:

dict={}

def add_and_multiply (a, b):
sum=a+b
product=a*b
dict[sum]=product
print(dict)
return dict


num1 = input("Enter Number 1:")
num2 = input("Enter Number 2:")
result = {}
result = add_and_multiply(int(num1), int(num2))

for k, v in dict.items():
print("Sum:", k, "and Product is:", v)

deepaksrinivasan
Автор

pls i need to check and download the answers, i can not find it on the mentioned link. please help

mohamedsherif
Автор

how can be print dictionary in same way as i declear it

Mohitraj-kqjn
Автор

assignment
#1
d={}
n=int(input("enter no of records: "))

for i in range(n):

global a, b
a=input("enter name ")
b=int(input("enter age "))
i=i+1
d[a] = b
print(d)

r=str(input("enter search name: "))
if r in d:
print(d[r])
else:
print("no match found")

#2
a=int(input("enter 1st number: "))
b=int(input("enter 2nd number: "))

def add_and_multiply(a, b):
add=a+b
multiply=a%b
return add, multiply

n=add_and_multiply(a, b)

print(n)

afrozkhan.
Автор

Sir I need solution for below question. Can you please help me?

"probab_to_cate = {0.72: 'Admit',

0.72: 'NotAdmit'}

df['tmp'] = df['Chance of Admit '].map(probab_to_cate)

y = df['tmp']

I want to map probabilities upto 0.72 should come equal to "Admit" and all below than 0.72 should be equal to equal to "NotAdmit"
. I tried above code which is returning only 0.72 = equal to " Admit". Can you correct this code please.

piousringlearning
Автор

family = {"dad": 65, "mom": 54, "sister": 31, "brother": 26}
print("Enter a new member and assign an age")
new_member = input("Enter new member : ")
age = input("Enter persons age : ")
age = int(age)
family[new_member] = age
print(family)
print("Enter family member name, I will tell the age")
query_name = input("Enter any member from your family : ")
print("The age of ", query_name, "is", family[query_name])
for key in family:
print("Age of ", key, "is", family[key])

pablu_
Автор

Am i correct ?
Please confirm

Exercise : 1

name=str(input("Enter the name : "))
age=int(input("Enter the age :"))
family={"mom":36, "dad":56, "sis":22, "bro":19, "me":25}

family[name]=age
print(family)

find=str(input("Enter name to find age : "))
print("Age of", find, "is", family[find])

print()

for k, v in family.items():
print("Name:", k, "Age:", v)


Exercise : 2

def add_and_multiply(a=0, b=0):
print("Addition:", a+b)
print("Multiplication:", a*b)

x=int(input("Enter 1st number :"))
y=int(input("Enter 2nd number :"))
num=add_and_multiply(x, y)

calistussolomon
Автор

My name is Samir and when he checked "samir" in d
Haha

samirphuyal
Автор

number_of_family_memebers = int(input("Enter number of family members: "))
dic_of_family_members = {}
for i in
name = input('Enter name :')
age = int(input('Enter age: '))
dic_of_family_members[name] = age
query = input('Enter Name you want to query:')
if query in dic_of_family_members:
print('Age of', query, dic_of_family_members[query])
else:
print('I don''t know the age of', query)
print(dic_of_family_members)








def add_and_multiply(x, y):
return x + y, x * y




result = add_and_multiply(3, 5)
print(type(result))
print(result[0])
print(result[1])

nikunj