Python Learning
Open in Telegram
Python learning resources Beginner to advanced Python guides, cheatsheets, books and projects. For data science, backend and automation. Join π https://rebrand.ly/bigdatachannels DMCA: @disclosure_bds Contact: @mldatascientist
Show more5 842
Subscribers
No data24 hours
+57 days
No data30 days
Posts Archive
5 843
Using tuples as keys in dictionaries
Since tuples are hashable, and list is not, we must use tuple as the key if we need to create a composite key to use in a dictionary.
Example: We would come across a composite key if we need to create a telephone directory that maps, first-name, last-name, pairs of telephone numbers, etc. Assuming that we have declared the variables as last and first number, we could write a dictionary assignment statement as shown below:
directory[last,first] = numberInside the brackets, the expression is a tuple. We could use tuple assignment in a for loop to navigate this dictionary.
for last, first in directory: print first, last, directory[last, first]This loop navigates the keys in the directory, which are tuples. It assigns the elements of each tuple to last and first and then prints the name and corresponding telephone number. Tuples and dictionary Dictionary can return the list of tuples by calling items, where each tuple is a key value pair.
a = {'x':100, 'y':200}
b = list(a.items())
print(b)
π Read Online
#Python #python_3
βββββββββββββ
Join @python_bds for more cool data science materials.
*This channel belongs to @bigdataspecialist group5 843
Python OOP : Object Oriented Programming in Python
Python Object Oriented programming OOP advanced / Scripting for projects / automation / interview questions / beginners
β° Free Online Course
π¬ video lessons
Rating βοΈ: 4.6 out 5
Students π¨βπ : 2,418
Duration β° : 2hr 10min of on-demand video
Created by π¨βπ«: Deepali Srivastava
π COURSE LINK
#python #programming #OOP
ββββββββββββββ
πJoin @python_bds for moreπ
5 843
Comparing tuples
A comparison operator in Python can work with tuples.
The comparison starts with a first element of each tuple. If they do not compare to =,< or > then it proceed to the second element and so on.
It starts with comparing the first element from each of the tuples
Letβs study this with an example-
#case 1
a=(5,6)
b=(1,4)
if (a>b):print("a is bigger")
else: print("b is bigger")
#case 2
a=(5,6)
b=(5,4)
if (a>b):print("a is bigger")
else: print ("b is bigger")
#case 3
a=(5,6)
b=(6,4)
if (a>b):print("a is bigger")
else: print("b is bigger")
Case1: Comparison starts with a first element of each tuple. In this case 5>1, so the output a is bigger
Case 2: Comparison starts with a first element of each tuple. In this case 5>5 which is inconclusive. So it proceeds to the next element. 6>4, so the output a is bigger
Case 3: Comparison starts with a first element of each tuple. In this case 5>6 which is false. So it goes into the else block and prints βb is bigger.β
π Read Online #Python #python_3 βββββββββββββ Join @python_bds for more cool data science materials. *This channel belongs to @bigdataspecialist group
5 843
Learn Python Programming for Ultimate Beginners
Jumpstart your Python programming career . If you are a complete beginner & want to learn Python coding from scratch
β° Free Online Course
π¬ video lessons
Rating βοΈ: 4.6 out 5
Students π¨βπ : 1,455
Duration β° : 1hr 33min of on-demand video
Created by π¨βπ«: Mazhar Hussain
π COURSE LINK
#python #programming
ββββββββββββββ
πJoin @python_bds for moreπ
Available now! Telegram Research 2025 β the year's key insights 
