Learn Python Coding
38.9K subscribers
615 photos
27 videos
24 files
370 links
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
The Python library itertools contains many useful functions. 🐍✨

One of them is compress(), which returns an iterator over the elements from data, for which the corresponding element in selectors is equal to True. πŸ”πŸ’»

Here's an example: πŸ“πŸ‘‡

#Python #Programming #Itertools #Coding #Tech #DataScience
πŸ”₯2
Cheat sheet on the basics of Python: πŸπŸ“š

basic syntax and language rules πŸ“
scalar types β€” basic data types (int, float, bool, str, NoneType) πŸ”’

datetime β€” working with date and time πŸ“…β°

data structures β€” Python data structures (list, tuple, dict, set) πŸ—„

list β€” mutable lists for storing data collections πŸ“‹
tuple β€” immutable sequences of values πŸ”’
dict (hash map) β€” storing data in a key-value format πŸ—
set β€” unique elements without order πŸ”˜

slicing β€” obtaining parts of sequences through indices and step βœ‚οΈ

module/library β€” connecting modules and libraries πŸ”Œ

help functions β€” using help() and dir() to explore the Python API πŸ› 

#Python #Coding #DataScience #Programming #Tech #DevCommunity
❀5πŸ”₯3πŸ‘2
Do you know that Python can shift sequences without slicing and creating new lists? πŸ€”

When you need to cyclically shift data, many use slicing:

data = data[-1:] + data[:-1]

But deque.rotate() does this at the level of the data structure and usually works more efficiently for cyclical operations. πŸš€

q.rotate(1)

A negative value rotates the queue in the other direction. ⬅️

q.rotate(-2)

This is useful for ring buffers, task schedulers, cyclical queues, and round-robin algorithms. πŸ”„

workers.rotate(-1)

πŸ”₯ deque.rotate() allows you to implement cyclical data structures without manual index logic and without creating new lists. πŸ’‘

#Python #Programming #Deque #CodingTips #Tech #DevCommunity
❀7
How to check for the presence of subclasses in Python? 🐍🧐

Here's how you can do it:

import inspect

def has_subclasses(cls):
return any(issubclass(sub, cls) for sub in inspect.getmembers(sys.modules[cls.__module__], inspect.isclass))

This function uses the inspect module to find all subclasses of the given class. πŸ› οΈ

#Python #Programming #Subclasses #Coding #Dev #Tech
❀3πŸ‘1
πŸ“‚ Reminder about Python map()!

map() β€” a built-in function that applies the specified function to each element of an iterable object (list, tuple, set, etc.).

The picture shows the basic syntax, an example of use with lambda, and a typical case β€” data transformation without a manual for loop.

Save it to quickly remember the syntax!

πŸπŸ’»πŸ—ΊοΈ #Python #Coding #Programming #LearnToCode #DevTips #Tech
❀5πŸ‘1