Shafik _


  • Understanding Deep Copy and Shallow Copy in Python: A Guide for Beginners

    In Python, creating a copy of an object using the assignment operator (=) does not create a new object. Instead, it only shares the reference of the original object to the new variable, leading to potential changes to the original object if modifications are made to the new variable. To avoid this issue, Python offers two copy methods: shallow copy and deep copy. Shallow copy creates new objects that store the original objects' reference, while deep copy creates a new object and recursively adds copies of nested objects present in the original elements. Python's copy module provides the copy() and deepcopy() methods for implementing shallow and deep copy, respectively. This guide explores the differences between shallow and deep copies and how to use the copy module to create copies of objects in Python.

    Dec 7, 2022 · 3 min(s) ·  #python
  • A Comprehensive Guide to Implementing Stack in Python: Methods, Operations, and Applications

    Stack is a popular data structure used in various programming languages, including Python. In this comprehensive guide, we explore the different ways to implement stack in Python using methods such as list, collections.deque, and queue.LifoQueue. We also discuss the basic operations of stack, including PUSH, POP, TOP, EMPTY, FULL, and SIZE, and how to implement them using each method. Additionally, we delve into the applications of stack in different areas such as browsers, compilers, function call and return processes, backtracking procedures, memory management, expression conversion, and graph algorithms. Furthermore, we explain how to use Python stack in multi-threaded programs and highlight the importance of choosing the appropriate implementation method based on the specific use case.

    Sep 30, 2022 · 8 min(s) ·  #python
  • Python: Understanding Generators and Iterators for Efficient Iteration

    Learn about Python iterators and generators. An iterator is an object that iterates through other objects like lists, tuples, dicts, and sets, and implements the iterator protocol with the __iter__() and __next__() methods. Generators are a simpler way to create iterators, where a normal function with yield statements is used to create an object that can be iterated over one value at a time. This allows for memory-efficient iteration and is useful for reading large files. The state of a generator function is remembered, and the previously yielded variable is incremented and yielded again when __next__() is called. The article covers the properties of flex containers and items in CSS, such as flex-direction, flex-wrap, flex-flow, justify-content, align-items, align-content, order, flex-grow, flex-shrink, flex-basis, flex, and align-self.

    Dec 16, 2019 · 3 min(s) ·  #python