PyNotes
259 subscribers
125 photos
7 videos
1 file
60 links
**Code is communication**
admin: @Xojarbu
https://t.me/solutions_py for problem solutions
Download Telegram
#heapq
Title: heapq

The most important feature of a heap is that heap[0] is always the smallest item.

heapq.heappop()-pops off the first item and replaces it with the next smallest item (an operation that
requires O(log N) operations where N is the size of the heap)
source: Python cookbook
#dicts

Title: Calculating dicts
prices = {
'ACME': 45.23,
'AAPL': 612.78,
'IBM': 205.55,
'HPQ': 37.20,
'FB': 10.75
}
Get min from dict:
min_price = min(zip(prices.values(), prices.keys())) 
# min_price is (10.75, 'FB')

Get max from dict

max_price = max(zip(prices.values(), prices.keys())) 
# max_price is (612.78, 'AAPL')


Sort Dict:
prices_sorted = sorted(zip(prices.values(), prices.keys()))

πŸ“Œ be aware that zip() creates an iterator that can only be consumed once. If you call zip variable next time, it will return empty obj.
#dicts
Title: Comparing dictionaries
Dictionary keys() and items() support common set operations such as unions, intersections, and differences.

values()
method of a dictionary does not support the set operations, therefore we cannot perform those operations with dictionary values.

Source: Python Cookbook
Title: Remove duplicates from list, without changing items order

You can do the same with set(items), but it doesn’t preserve any kind of ordering. Output will be:
{1, 2, 10, 5, 9}

! This works with hashable items.

Source: Python cookbook
#counter #most_common
Find Most Frequently repeated Items in
a Sequence
Transforming and reducing data

To calculate the sum of
squares, do the following:

nums = [1, 2, 3, 4, 5]
s = sum(x * x for x in nums)

instead of:
s = sum((x * x for x in nums)) or
s = sum([x * x for x in nums])

It introduces an extra step and creates an extra list or tuple.

Source: Python cookbook
#class #methods
Title: __repr__ with __str__


β€”When we call Class it is represented by __str__ method by default, if there is not __str__ method, __repr__() method will be called.
β€”The __repr__() method returns the code representation of an instance, The __str__() method converts the instance to a string

! A good example is provided above

source: "Python Cookbook:
MRO (method resolution order) list is simply a linear ordering of all the base classes
#memory_management
Title: String interning
To alleviate memory that can be quickly consumed by strings, Python implements string interning
β€” A string will be interned if it is a compile-time constant, is not the production of constant folding or is not longer than 20 characters, and consists exclusively of ASCII letters, digits, or underscores.
β€”Empty strings are interned.
Source
Title: Namespaces
A namespace is a system that has a unique name for each and every object in Python. An object might be a variable or a method.

There are 3 types of namespaces:
built-in namespaces
global namespaces
local namespaces

e.g
var1 = 5 # global namespace
def some_func():
var2 = 6
# local namespace

The built-in namespace is always available when Python is running. You can list all built-in namespaces with dir(__builtins__)

Source
Title: getters and setters in Python
Getters
and Setters are used to ensure data encapsulation in OOP.
In python they are not the same as in other languages, because private variables are not hidden in python.
Getters and Setters are used to add validation for getting and setting values or to avoid direct access of a class field.

πŸ“Œ get() and set() methods don't fully work as getters and setters. In this case, python has a special function property()

Sources: Python cookbook and geeksforgeeks
#memory_management
Title:
Integer Caching in Python

The Python implementation front loads an array of integers between -5 to 256. Hence, variables referring to an integer within the range would be pointing to the same object that already exists in memory

Source
#memory_management
The Tricky Case with Operators πŸ˜ƒ

Source
Assalomu alaykum
leetcode.com yoki binarysearch.com da masala ishlab yuradiganlar bo'lsa,
@dilshodbek_xojametov DIlshodbek botga ulangan gruppa yaratganlar, qiziquvchilar bo'lsa lichkalariga o'zingizni leetcode dagi yoki binarysearch.com dagi usernamizni jo'natsangiz gruppaga qo'shib qo'yishadi.

Guruh qoidasi:
- Har kuni kamida 1 ta misol yechish
- 2 kun ichida bitta ham misol yechmasa guruhdan kick bo'ladi

Guruhdan maqsad masala yechishni eslatib turish va ko'proq masala ishlashga qiziqtirish. O'zingizni reytingizni kuzatib yursangiz ham bo'ladi.
❗️RECOMMENDED
Forwarded from Azim Pulat
Facebook'dan Offer Oldim πŸŽ‰

Manba:
azimjon.com/blog/facebookdan-offer-oldim
Today I have joined EPAM systems team as a software engineer, Sharing what I was learning in this channel helped me a lot during my interviews. Will do my best to continue sharing new knowledges πŸ˜ƒ
Time complexity for List operations in Python
Assalomu alaykum!
Oxirgi kunlarda juda ko'p so'ralgan savol bo'lgani uchun o'zimni intervyular haqida hozirgacha bo'lgan fikrlarimni va birozgina olgan tajribamni sizlar bilan ulashmoqchiman 😊

Demak boshladik ⏳

Mavzu: Texnik intervyularda Python dasturlash tilida backend dasturchilaridan so'rashlari mumkin bo'lgan mavzular to'plami yoki o'rganishimiz kerak bo'lgan mavzular to'plami desak ham to'g'riroq bo'ladi.


>> Data types in python
-difference between list and tuple etc;
-difference between mutable and immutable data types and how they are saved in the memory;
- sorting list/tuple/dictionaries;
>> id() function
>> Decorators
>> Iterators with Generators
-- difference between iterators and iterables
>> Python classes(self in class methods)
>> Context managers in Python
>> Threads/Processes/GIL
>> Garbage collectors
>> Memory management in Python
>> Reference counting in python
>> Questions related to Testing

βž• PROBLEM SOLVING

Qo'shimcha mavzular:

-- Big O notation
-- OOP/SOLID principles
-- CI/CD
-- Docker (images, containers)
-- Methodologies (Agile, Scrum)

--Database related questions:
> Relational database with non-relational databses
> Indexing
> queries with JOIN

βž• agar ishlatgan bo'lsangiz python frameworklari (django, FastAPi, Flask) va ularning ORMiga oid savollar ham bo'lishi mumkin.

va boshqalar )


πŸ“Œ Shu yerda tavsiya: bu mavzularni faqat intervyu uchun o'rganmang, juda tez vaqt ichida yodingizdan ko'tarilib ketishi mumkin, aksincha real proyektlarda qo'llashga yoki kimgadur tushuntirib berishga harakat qiling shunda yodingizda ko'proq qoladi.

πŸ“ŒπŸ“Œ Qo'shimcha tavsiya )
Bu mavzularni o'zini alohida izlab o'rgangandan ko'ra kitoblardan o'rganganimiz ancha foydaliroq va o'zimiz kutgandan ham ko'proq narsa olishimiz mumkin.

Hozircha men tavsiya qila oladigan resurslar:
Python_101 (by Michael Driscoll)
Python Coockbook (by David Beazley and Brian K. Jones)
Python tricks (Dan Badar)
Python basics: https://stepik.org/course/512/syllabus
Learning Python: Powerful Object-Oriented Programming
---------------------------------------------------------

Intervyular juda foydali deb o'ylayman, ayniqsa dasturchilar uchun. Sizni o'z sohangizda o'sishingizga yordam beradi va qayerlarda kamchiligingiz bor va nimalarni mustahkamlashingiz kerakligini yaqqol ko'rsatib beradi (xuddi peshonangizni devorga urgandek πŸ˜…).

Intervyularda olgan natijani to'g'ri qabul qiling, o'zingizga bo'lgan ishonchni so'ndirishiga qo'ymang yoki juda oson o'tgan bo'lsa o'zingizga ortiqcha baho berib miyangizni tormozlab qo'ymang.

Intervyulardan yiqilish yaxshiπŸ˜ƒ, Chunki keyingilarida yiqilishdan qo'rqmaysiz uje yiqilib ko'rgan bo'lasiz va yanayam yaxshiroq o'rganishingizga turtki bo'ladi.

Haqiqiy intervyudan oldin, do'stlaringizdan yoki tajribasi sizdan ko'proq insonlardan mock intervyular olib ko'rishlarini iltimos qiling, juda kotta yordam beradi bu ham. Hamda bitta joyga emas bir nechta joylarga apply qilib ko'rish kerak.
πŸ‘3πŸ”₯2
#call_stack

The call stack. This is the main structure of a running Python program. It has one itemβ€”a "frame"β€”for each currently active function call, with the bottom of the stack being the entry point of the program. Every function call pushes a new frame onto the call stack, and every time a function call returns, its frame is popped off.

Sourse1, source2