ChatterOne
  • Member for 7 years
  • Last seen more than a month ago
Create the English word for a number
11 votes

You have quite a big bug there. In this part: elif 100 <= num <= 999: hundreds, below_hundred = divmod(num, 100) tens, below_ten = divmod(below_hundred, 10) If you have anything where ...

View answer
Get value from dictionary given a list of nested keys
Accepted answer
11 votes

Unless I'm missing something you'd like to implement, I would go for a simple loop instead of using recursion: def nested_get(input_dict, nested_key): internal_dict_value = input_dict for k ...

View answer
Magic Trick (Google Code Jam 2014 QR Problem A) in Python
Accepted answer
11 votes

Naming: main is reserved so that's ok, but main2 makes no sense. The name should be a hint about what the function does, I'd go for guess_card. Since there's no mention of a file input, I'd say go for ...

View answer
Caesar Cypher in Python
Accepted answer
9 votes

I'd say the code is not bad, just a few style issues and a couple of practical things. You don't need two lines to lowercase the input string, you can do directly inp = input('Input the text you want ...

View answer
Noughts and Crosses in Python using the pygame module
Accepted answer
6 votes

I'd remove those comments, because they don't really add anything (having something like Initialises the pygame module near pygame.init() is not really helpful). The only one I'd keep is clicked = ...

View answer
Find highly composite number using Python 3
Accepted answer
6 votes

As you said, the naming is not good and the code can be condensed and optimized. You don't need to keep all the lists, you just need the count You can split get_divisors so you have another function ...

View answer
Snake game in Pygame
Accepted answer
6 votes

There is quite a lot of code, so I'll point out the first few things that I notice. Naming: you have some constants all upper case which is good, but you also have constants that are lower case and ...

View answer
Printing staircase revisited
6 votes

No need for the additional for loops: function StairCase(n) { var s = ''; for (var i = 1; i <= n; i++) { s += ' '.repeat(n - i) + '#'.repeat(i) + '\n'; } return s; } ...

View answer
Breakout clone in pygame
5 votes

#level1 global level1 The comment here is not useful, if you have a variable level1, well... that's level1, right? The same goes for all your other comments in the code. You should think of comments ...

View answer
Yet another Pascal triangle in Python written in functional programming pattern
Accepted answer
5 votes

If you look at the documentation for lru_cache you'll see that it says that it can save time when an expensive or I/O bound function is periodically called with the same arguments. You keep calling ...

View answer
File copy in Python for slow networks
Accepted answer
5 votes

I don't think there is much more to do/check in terms of functionality, but I'd like to point out a few coding style issues (in my opinion). Be careful when checking paths. If you are taking any kind ...

View answer
Looking for a pattern in a list
Accepted answer
5 votes

I guess that the first part of your code is just to initialize the sample data. Then here are a few things: Separate initialization and main loop. I know this is just an exercise, but always doing ...

View answer
Bubble sort examination
Accepted answer
5 votes

As @Zeta said, only your examiner can tell you why he wasn't satisfied. But here are a couple of suggestions anyway: Variable names are important and myArray doesn't mean much. You can try inputArray ...

View answer
Finding the longest palindromic substring
Accepted answer
4 votes

In terms of efficiency, I like the code. I'd just fix a few stylistic issues: Naming: l, a, s don't say anything about what the variable means. Also, you named your function palindrome, but that's ...

View answer
Beginner code for MadLibs game
4 votes

You could use a bit less comments, most of the code is self-explnatory You could also use a bit more split of the code into functions, e.g. a function to create a default file This is a full script, ...

View answer
Dynamic programming based range minimum query
4 votes

Just some really quick thoughts. This: j = 0 while 2 ** j - 1 < len(numbers): j += 1 j -= 1 can be written as: from math import log j = int(log(len_numbers, 2)) You're repeating step - 1 ...

View answer
Check "five in a row" for a 15x15 chess board
4 votes

A few suggestions: Can both players win? If not, how do you decide which one to check first? If they can, if both of them have already won in the first check, no need to go on, just return True, True....

View answer
TicTacToe in Python3 w/ Simple AI
Accepted answer
4 votes

First of all, nice ingenuity on displaying an almost graphical board, that's good for a beginner. The intInput function should follow PEP8 and be something like 'get_int_input'. Also, since you want ...

View answer
Crawl site getting URL and status code
Accepted answer
4 votes

You're taking for granted that a link will be '<a href="http:/', which is definitely not always the case. What about https:// for example, or if you have something like '<a class="visited" href="...

View answer
My minesweeper implementation in Javascript
Accepted answer
4 votes

Here are my personal thoughts: Naming: it's probably better to have placeBombs instead of initBombs, because you have a function called placeBomb. Sometimes you use i and j , others you use x and y, ...

View answer
String manipulation in Python
Accepted answer
3 votes

How about this? mac_address = mac_address[19:].translate(str.maketrans("", "", "\n':")).strip()

View answer
Breadth First Search to find connected primes
3 votes

Just to add to @alecxe's answer, the sieve function can be re-written as: def sieve(n): numbers = range(2, n ** 0.5) for prime in numbers: for i in range(prime ** 2, n, prime): ...

View answer
Classifying files in a directory by file extension
3 votes

Assuming that: you only have two possible results you can't have two files with the same name Then you only need to iterate once and then make the set difference between the results. Something like: ...

View answer
Continuous sequence against target number
Accepted answer
3 votes

In case there's no acceptable sequence, you have to go through all the elements anyway, so it can't be lower than O(n), and your code is already O(n). The only optimization that you could add is a ...

View answer
Merge two sorted lists of numbers
Accepted answer
3 votes

If you only want to support same-length array, you should do so explicitly, either by returning and empty list or an error code It's harder to read if you have to go back in the code to check what i, ...

View answer
Converting an integer to Greek and Roman numerals
3 votes

I wouldn't use if __name__ == '__main__': for extended logic. I'd put just a main() in there and do the checks/call the functions from there. Your script is supposed to have user input and output. ...

View answer
Google Analytics tracking for HTML 5 video player
Accepted answer
3 votes

I would use a single bind: $("#videoplayer").bind("timeupdate", function() { var currentTime = this.currentTime; if (currentTime > 0.75 * (this.duration)) { a = a + 1; ...

View answer
Custom Logger class
2 votes

Just to add to the other answers, not sure if you've considered this, but keep in mind that the file name will be the same unless you create a new instance of your class. That means that if your ...

View answer
Linking two databases based on street addresses
2 votes

All you need to do is: normalize the two files, so that the content is in the same format (that means removing whatever you think should not be there, like n°, de l' and so on) combine the two files ...

View answer
Python - Random Number Guessing Game
2 votes

I'd say the code itself is not bad but there are a few things to keep in mind. i is a bad name for a string. Also, you don't need it in the instructions function, you can just print the string. The ...

View answer