def sorted_(data, l, series=False, i=False): loc = Locale.forLanguageTag(l) collator = Collator.createInstance(loc) if isinstance(data, dict): sorted_data = sorted(data.items(), key=lambda x: collator.getSortKey(x[i])) return dict(sorted_data)
def sorted_(data, l, series=False): if (language_tailorings.get(l)): tailored_lang = language_tailorings.get(l) tailored_rules = collation_tailorings.get(tailored_lang) collator = RuleBasedCollator(tailored_rules) if isinstance(data, list) or isinstance(data, tuple) or isinstance( data, str): sorted_data = sorted(data, key=collator.getSortKey) elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): sorted_data = df_sort(data, series, collator.getSortKey) elif Locale.forLanguageTag(l): loc = Locale.forLanguageTag(l) collator = Collator.createInstance(loc) if isinstance(data, list) or isinstance(data, tuple) or isinstance( data, str): sorted_data = sorted(data, key=collator.getSortKey) elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): sorted_data = df_sort(data, series, collator.getSortKey) else: if isinstance(data, list) or isinstance(data, tuple) or isinstance( data, str): sorted_data = sorted(data) elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): sorted_data = data.sort_values(by=series) if isinstance(data, list): return sorted_data elif isinstance(data, tuple): return tuple(sorted_data) elif isinstance(data, str): return ''.join(sorted_data) else: return sorted_data # def sorted_(data,l, series=False, i=False): # if (language_tailorings.get(l)): # tailored_lang = language_tailorings.get(l) # tailored_rules = collation_tailorings.get(tailored_lang) # collator = RuleBasedCollator(tailored_rules) # if isinstance(data, list) or isinstance(data, tuple) or isinstance(data, str): # sorted_data = sorted(data, key=collator.getSortKey) # elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): # sorted_data = df_sort(data, series, collator.getSortKey) # elif isinstance(data, dict): # sorted_data = sorted(data.items(), key = lambda x : collator.getSortKey(x[i])) # elif Locale.forLanguageTag(l): # loc = Locale.forLanguageTag(l) # collator = Collator.createInstance(loc) # if isinstance(data, list) or isinstance(data, tuple) or isinstance(data, str): # sorted_data = sorted(data, key=collator.getSortKey) # elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): # sorted_data = df_sort(data, series, collator.getSortKey) # elif isinstance(data, dict): # sorted_data = sorted(data.items(), key = lambda x : collator.getSortKey(x[i])) # else: # if isinstance(data, list) or isinstance(data, tuple) or isinstance(data, str): # sorted_data = sorted(data) # elif isinstance(data, pd.DataFrame) or isinstance(data, pd.Series): # sorted_data = data.sort_values(by=series) # elif isinstance(data, dict): # sorted_data = sorted(data.items(), key = lambda x : x[i]) # if isinstance(data, list): # return sorted_data # elif isinstance(data, tuple): # return tuple(sorted_data) # elif isinstance(data, str): # return ''.join(sorted_data) # elif isinstance(data, dict): # return dict(sorted_data) # else: # return sorted_data # How to handle numpy arrays? # Would it be better to use df.sort_values() for Pandas dataframes and series? # https://stackoverflow.com/questions/62147537/how-do-i-do-a-natural-sort-in-pyicu # https://gist.github.com/dpk/8325992 # https://ianwscott.blog/2015/04/30/python-programming-proper-alphabetical-sorting-for-polytonic-greek/