2022 Developer Survey is open! Take survey.

# Tag Info

Accepted

### Printing a list as "a, b, c." using Python

TL;DR: Despite this being the currently accepted & highest voted answer, these methods from this answer and variations (1, 2) of it: ...
• 30.4k
Accepted

### Rendering a person's time clock record in HTML, with many color-coded conditions

There are a few good practices that will help this code out. Close the HTML tags that you open - generate valid HTML Newer browsers will probably render your content properly, but older browsers may ...
• 516

### Printing a list as "a, b, c." using Python

The best solution is to use str.join(), using ', ' as the joining string. ...
• 41.6k
Accepted

### Program to print a Python list as "a, b, and c"

# defining possible lists Don't write comments that describe what the code does; we can see the code, we know what it's doing. If you ever need comments, it's ...
• 13.8k

### Function to format the local time

First of all, the parenthesis around LocalDateTime.now() are useless. Now, let's see what we're really doing here: ...
• 58.1k

### Rendering a person's time clock record in HTML, with many color-coded conditions

That's a big mess of conditionals. Hopefully they all match the comments near them, though given typical code that's likely not the case. You are repeating a lot of HTML code that could be addressed ...
• 8,723
Accepted

### Printing binary trees

First of all, in my opinion, both the algorithm is nice and interesting, and the code is really well-written, broken down into easily understandable functions! Well done! The only addition that I can ...
• 1,635
Accepted

### Prettify JSON class

Thanks for editing the question. I have few ideas how you might want to polish your code. std::string base class It caught my eye that JSONPretify is derived ...
• 897

### Show time in format yyyy-MM-ddThh:mm:ss.SSS

You can single-quote the 'T' to have it accepted as a String literal private final static String DATE_FORMAT = "yyyy-MM-dd'T'hh:mm:ss.SSS";
• 261
Accepted

### Show time in format yyyy-MM-ddThh:mm:ss.SSS

Don't reinvent the wheel, this is java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME. ...
• 831
Accepted

### Comma Code - Automate the Boring Stuff with Python

You've got an odd bug with your code. Given the 8th menu item from the greasy spoon café: spam = ["Spam", "Spam", "Spam", "egg", "Spam"] You will get: and ...
• 30.4k

### Setting a default value if a variable is empty

Lo and behold, the power of PHP 7's null coalesce operator! It is also called the isset ternary operator, for obvious reasons. Here's a passage from php.net's wiki page about it Proposal The coalesce,...
• 251
Accepted

### Format a timespan with up to two fields

What you want to do, is use early-returns (FTW). Also, let the formatter do the string work for you. Right tool for the job. Consider your code, rewritten in Ideone...: ...
• 96.7k
Accepted

### K&R 1-21 write an "entab" program

I see some things that could help you improve your program. Learn a recent version of C I still have my K&R first edition from 1978, however it would be a very poor choice to use for learning C ...
• 64.1k

### Cropping a message using array splits

This is much slower than necessary. It takes time to construct the array, and more to shorten the array word-by-word. It's easy to imagine how this would go if ...
• 4,145
Accepted

### Fantasy game inventory — Ch. 5 Automate the Boring Stuff

I am suggesting to use fstrings and the dictionary items() method. The print(f'{value} {key}') instead of ...
• 872
Accepted

### Converting time in number of minutes past midnight to HH:MM format

Following @Martin R's comment, I'll make my comment above a solution: printf already supports what you're trying to achieve with your if-then-else jungle: ...
• 871
Accepted

### Minimal printf for integer types in x86 assembly

If, for the sake of this exercise, codesize is the only thing that you care about, then I would dare suggest the following: For divq10, not having to reload the constant will save 5 bytes, and using <...
• 4,058

### Rendering a person's time clock record in HTML, with many color-coded conditions

The first if block can be narrowed by using a color variable; something like this: ...
• 251
Accepted

### Format RGB Long as hex string in VB6

The code you have works, and is very nicely-formatted. There are only two things I would change, stylistically speaking: Explicitly pass input parameters by value. This should have been the default, ...
• 4,429
Accepted

### Python class initialize with dict

Python and the power of unpacking may help you in this one, As it is unclear how your Class is used, I will give an example of how to initialize the dictionary with unpacking. This will work on any ...
• 11.4k
Accepted

### Pretty printing degrees input to radians

Your code looks more complicated than necessary and some of your special cases are really not needed. I will use an incremental development to avoid unnecessary code: The first version is just based ...
• 27k

### BigInteger formatting for endless tower defense game

Naming Interfaces are usually named starting with a capital I in .NET. ScientificFormatter Here you have ...
• 49.9k

### Program to print a Python list as "a, b, and c"

To expand on jonrsharpe's excellent answer, here is how you can make the function that does the actual work, printing the list comma separated with an "and" before the last item, more pythonic: ...
• 40.5k

### A CSharpish String.Format formatting helper

Two small things I noticed at a glance, both involve this code and it looks like it made it into your refactored version as well. ...
• 30.7k