1. Hey guys, Hope you all are doing great. 

    Algorithm To Convert Post-fix Expression into Infix expression:-

    1. Scan the Post-fix String from Left to Right.
    2. If the character is an Operand, then Push it on to the deque.
    3. If the character is an Operator, then Pop left Operator 1 and Operand 2 and concatenate them using Infix notation where the Operator is in between the Two Operands.
    4. The resultant expression is then pushed on the deque.
    5. Repeat the above steps till the Post-fix string is not scanned completely.
    6. Use parentheses properly to ensure correct order for evaluating the final expression.

    Code Implementation:-


    # -*- coding: utf-8 -*-
    """
    Created on Wed Dec 22 22:58:14 2018
    @author: Kurtesy
    """
    from collections import deque
    OPERATORS = '+-/*'
    
    
    def postfix_to_infix(my_queue):
        if len(my_queue) == 1:
            return my_queue
        variable_1 = my_queue.popleft()
        """Handles left to right operation"""
        if variable_1 in OPERATORS:
            operand2 = my_queue.pop()
            operand1 = my_queue.pop()
            my_queue.append(('(%s)' % ''.join([operand1, variable_1, operand2])))
            return postfix_to_infix(my_queue)
    
        """Handles previous expression and next operand"""
        variable_2 = my_queue.popleft()
        if variable_2 in OPERATORS:
            operand1 = my_queue.pop()
            my_queue.append(('(%s)' % ''.join([operand1, variable_2, variable_1])))
            return postfix_to_infix(my_queue)
    
        """Process complete expression"""
        operation = my_queue.popleft()
        my_queue.append(('(%s)' % ''.join([variable_1, operation, variable_2])))
        return postfix_to_infix(my_queue)
    
    
    def func(x):
        return eval()
    
    
    while 1:
        expression = input()
        """Input till # is enforced"""
        if '#' in expression:
            break
        queue = deque(expression)
        postfix = postfix_to_infix(queue)
        print(postfix.pop())
    



    Please let me know your feedback, on how i can improve and make it better. Till then!! Cheers!!
    0

    Add a comment

  2. Hey guys, Hope you all are doing great.
    As the first part of this series of Python package and installation we will cover pip vs Conda

    pip vs Conda

    pip
    • Python packages only. Compiles everything from source. Installs binary, wheel, the ones which pypi supply
    • Blessed by the core Python community (i.e., Python 3.4+ includes code that automatically boostraps pip).
    conda
    Python agnostic. The main focus of existing packages are for Python, and indeed conda itself is written in Python, but you can also have conda packages for C libraries, or R packages, or really anything.
    Installs binaries. There is a tool called conda build that builds packages from source, but conda install itself installs things from already built conda packages.
    External. Conda is the package manager of Anaconda, the Python distribution provided by Continuum Analytics, but it can be used outside of Anaconda too. You can use it with an existing Python installation by pip installing it (though this is not recommended unless you have a good reason to use an existing installation).
    In both cases:
    • Written in Python
    • Open source (conda is BSD and pip is MIT)

    The Difference... 

    pip Conda
    pip uses the official PyPI package index Conda uses the anaconda repo
    pip does not install the binaries and focus more on package installation. Conda allows you to install precompiled binaries that will work on your system, such as C Compiled binaries, etc.
    pip focusses just on package management and leaves environment management to other tools Conda also functions as an environment manager
    PyPI packages are actively updated Conda's repos generally lag behind PyPI



    To Summarize...

    pip is for Python only

    Conda is only for Anaconda + other scientific packages like R dependencies etc. NOT everyone needs Anaconda that already comes with Python. Anaconda is mostly for those who do Machine learning/deep learning etc. Casual Python dev won't run Anaconda on his laptop.



    Please let me know your feedback, on how i can improve and make it better. Till then!! Cheers!!
    0

    Add a comment

Loading