Skip to content

Instantly share code, notes, and snippets.

@sigmapie8
Created July 14, 2019 07:09
Show Gist options
  • Save sigmapie8/7cd7369fe9e536b5db97cbea04b0fa4b to your computer and use it in GitHub Desktop.
Save sigmapie8/7cd7369fe9e536b5db97cbea04b0fa4b to your computer and use it in GitHub Desktop.
Sorting files on the basis of date modified
def latest_post():
"""
returns the last modified post in posts directory
"""
posts_dic = dict()
for dirpath, dirnames, filenames in os.walk(posts_directory):
for dirname in dirnames:
posts_dic[dirname] = os.stat(dirpath+"/"+dirname).st_mtime
return max(posts_dic.keys(), key=(lambda x: posts_dic[x]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment