Created
October 10, 2018 09:00
-
-
Save martinholub/8fc7e111f16035de5d8a8c4c92e159fb to your computer and use it in GitHub Desktop.
Utilites for handling lists and filenames
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rm_ext(fname, ext = None): | |
"""Removes extension from filename""" | |
if not ext: | |
ext = re.match(".*\.(.*)$", fname).group(1) | |
else: | |
ext = ext.strip(".") | |
return re.sub("\." + ext + "$","", fname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def uniq_list(array): | |
""" Returns unique elements in list in original order | |
set() does not preserve order. In python 3.5, OrderedDict is implemented in C, | |
and thus acceptable alternative. For python 3.6+, it can be replaced with regular | |
dict as it became ordered. | |
References | |
https://stackoverflow.com/a/39835527/6877443 | |
""" | |
return list(OrderedDict.fromkeys(array)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment