Я могу представить только одно общее решение с отступом. Вы должны использовать моноширинный шрифт, и все символы обоих алфавитов должны быть одинакового размера. На самом деле функция PaddingRight просто добавляет указанное количество символов в строку. Но отображаемый размер строки также зависит от шрифта. Если вы используете моноширинный шрифт, он будет работать, в других случаях даже для латинских символов - нет. По моему мнению, лучше решать проблему для каждого конкретного вывода, который вы собираетесь использовать, потому что строка itsefl ничего не знает о том, как он будет отображаться, и более того, он не должен знать об этом.
Use set()
to remove duplicates if all values are hashable:
>>> your_list = ['one', 'two', 'one']
>>> len(your_list) != len(set(your_list))
True
my_list = ['one', 'two', 'one']
duplicates = []
for value in my_list:
if my_list.count(value) > 1:
if value not in duplicates:
duplicates.append(value)
print(duplicates) //["one"]
Recommended for short lists only:
any(thelist.count(x) > 1 for x in thelist)
Do not use on a long list -- it can take time proportional to the square of the number of items in the list!
For longer lists with hashable items (strings, numbers, &c):
def anydup(thelist):
seen = set()
for x in thelist:
if x in seen: return True
seen.add(x)
return False
If your items are not hashable (sublists, dicts, etc) it gets hairier, though it may still be possible to get O(N logN) if they're at least comparable. But you need to know or test the characteristics of the items (hashable or not, comparable or not) to get the best performance you can -- O(N) for hashables, O(N log N) for non-hashable comparables, otherwise it's down to O(N squared) and there's nothing one can do about it:-(.