New answers tagged

5 votes

Check how many days a country has been independent

Delete all of your comments. None of them make the code more obvious than just reading it. strftime is unused so don't import it. Consider using a dictionary of ...
user avatar
  • 49.5k
2 votes

Removing medications older than 180 days ago from a list

Bugs The code has at least two bugs. The first is when two adjacent list items are more than 6 months old, the second one will not be deleted. This occurs because when an item is deleted, the rest of ...
user avatar
  • 9,130
3 votes

Removing medications older than 180 days ago from a list

Use a list comprehension! When constructing lists in python by looping through others lists, its a lot more visually de-cluttered (not necessarily more performant) to just use python's list ...
user avatar
-1 votes

Removing medications older than 180 days ago from a list

Depends on how much you care about performance. If you really care, don't use Python. If you kind of care, use Pandas in Python. I cannot speak to how you load your data in Pandas because you haven't ...
user avatar
  • 49.5k
1 vote
Accepted

Clear output line in terminal after use for countdown (different length strings)

ANSI escape sequences are not necessary, and the so-called archaic method of using a carriage return is preferred. Avoid mixing sys.stdout with ...
user avatar
  • 49.5k
2 votes
Accepted

Convert string to date C++

Unnecessary use of wide strings In your example, there is no need to use wide strings for date_time_format and ss. Just use <...
user avatar
  • 33.2k
0 votes

12 hour to 24 hour time conversion

In production code you would never manually parse a datetime like that. Instead you would use a round-trip through the datetime built-in: ...
user avatar
  • 49.5k
1 vote
Accepted

12 hour to 24 hour time conversion

Program structure timeconversion is not a very descriptive function name. What is it converting from, and what is it converting to? I suggest ...
user avatar
4 votes
Accepted

Extract the last row in a dataframe with a timestamp before some given time

Don't use np.random; it's deprecated in favour of the new generator methods in the family of default_rng. ...
user avatar
  • 49.5k

Top 50 recent answers are included