Code Monkey home page Code Monkey logo

Comments (16)

miedzinski avatar miedzinski commented on May 22, 2024 1

@dynamitechetan, Pycoder's Weekly, issue #227.

from python.

harshildarji avatar harshildarji commented on May 22, 2024 1

@SergeyTsaplin Merged!

from python.

miedzinski avatar miedzinski commented on May 22, 2024 1

I recommend reading this and then this.

from python.

topaz1874 avatar topaz1874 commented on May 22, 2024

Cant agree more, even from a newbie like me ,still can tell these code can write much better.

from python.

dynamitechetan avatar dynamitechetan commented on May 22, 2024

We all are learners, if you think something is wrong please send a pull request and make this more efficient.

from python.

harshildarji avatar harshildarji commented on May 22, 2024

Agree with @dynamitechetan
If you've found any problem in our code, then I request you to make a pull request.

from python.

AnupKumarPanwar avatar AnupKumarPanwar commented on May 22, 2024

Yeah exactly you can think of it as an Open Source book

from python.

SergeyTsaplin avatar SergeyTsaplin commented on May 22, 2024

I made selection sort more pythonic, please merge it #5

Later I can make more but now I haven't got enough time for it

from python.

miedzinski avatar miedzinski commented on May 22, 2024

@dynamitechetan, no offence, but I think there is something wrong in every line in this repository. Somehow this repository ended up in my favorite weekly newsletter, so I'm assuming this was posted somewhere as a resource for Python novices. Unfortunately, this "open source book" isn't ready to be published and teaches many bad habits.

Looking at binsearch, flake8 output:

30:1: W391 blank line at end of file
2:1: W293 blank line contains whitespace
6:1: W293 blank line contains whitespace
8:1: W293 blank line contains whitespace
14:1: W293 blank line contains whitespace
16:1: W293 blank line contains whitespace
20:1: W293 blank line contains whitespace
28:7: E225 missing whitespace around operator
28:11: E201 whitespace after '('
11:14: E111 indentation is not a multiple of four
12:14: E111 indentation is not a multiple of four
7:16: E225 missing whitespace around operator
21:18: E712 comparison to False should be 'if cond is False:' or 'if not cond:'

It looks like there is a warning every second line, including those empty. It's not good.
Regarding efficiency, I don't think it is that important when showing Python to newcomers. Code should be friendly and clean. Anyway, this could be rewritten using bultin modules and we would achieve two things for free ("C speed" and reducing line count). Copy-pasting from Python docs:

import bisect


def binary_search(sequence, value):
    index = bisect.bisect_left(sequence, value)
    if index != len(sequence) and sequence[index] == value:
        return index
    raise ValueError

Using this, we can easily write another function, which returns True/False depending on presence of item in sequence (just like current implementation as of 4c2c3c5)

def bin_exists(sequence, value):
    try:
        binary_search(sequence, value)
    except ValueError:
        return False
    else:
        return True

Voilà, done. Side-effects free, clean, concise and pythonic.

Add some docstrings, examples of usage, if __name__ == '__main__' idiom for testing from terminal and it's ready for PR.

Big difference, IMO.

from python.

dynamitechetan avatar dynamitechetan commented on May 22, 2024

@miedzinski I will try to fix it asap.
And I would also like to know which weekly newsletter this repo got posted.
Thank you for your help!

from python.

SergeyTsaplin avatar SergeyTsaplin commented on May 22, 2024

Made binary_search algo usual way. Also binary search method used stdlib added (suggested to @miedzinski comment) - binary_search - pure implementation binary_search_std_lib - implementation using stdlib's bisect
Just merge #6

from python.

miedzinski avatar miedzinski commented on May 22, 2024

@SergeyTsaplin, much better. But you introduced one, very bad, thing to with new implementation. Your code is O(nlogn), because of assertion which sorts the sequence. You could do it O(n), but in the same way you could implement linear search, which beats the purpose of doing binary search in first place. Just drop it.

from python.

SergeyTsaplin avatar SergeyTsaplin commented on May 22, 2024

Guys, don't name files such way please:

  • Simple Substitution Cipher.py
  • BubbleSort.py etc

First example is absolutely amateurish. Second - is not pythonic
If you see such pull request - just reject it. Also it's very useful to use some CI-service to prevent bad code

from python.

harshildarji avatar harshildarji commented on May 22, 2024

@SergeyTsaplin Thank you for suggestion. Actually it's my mistake, and I just solved it.

from python.

harshildarji avatar harshildarji commented on May 22, 2024

@SergeyTsaplin I've included test cases in all cipher scripts and this tests are running well locally as shown in below image:
capture

But, when I commit and push the same, Travis says that build failed.
Can you please take a look at this?

from python.

miedzinski avatar miedzinski commented on May 22, 2024

Read the build log. It's explained there.


I am closing this. Clearly some changes to code were made.

from python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.