-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
%load -s to load specific functions or classes #4311
Changes from 7 commits
c88200d
adff808
8f03d11
04432cc
73c1ae4
348e90f
7391345
3ced24d
94fd6a9
f7cd9ed
f243434
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -724,3 +724,32 @@ def columnize(items, separator=' ', displaywidth=80): | |
fmatrix = [filter(None, x) for x in matrix] | ||
sjoin = lambda x : separator.join([ y.ljust(w, ' ') for y, w in zip(x, info['columns_width'])]) | ||
return '\n'.join(map(sjoin, fmatrix))+'\n' | ||
|
||
|
||
def get_text_list(list_, last_word='and', wrap_item_with=""): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No More seriously, I might include the surrounding spaces in |
||
""" | ||
Return a string with a natural enumeration of items | ||
|
||
>>> get_text_list(['a', 'b', 'c', 'd']) | ||
'a, b, c and d' | ||
>>> get_text_list(['a', 'b', 'c'], 'or') | ||
'a, b or c' | ||
>>> get_text_list(['a', 'b'], 'or') | ||
'a or b' | ||
>>> get_text_list(['a']) | ||
'a' | ||
>>> get_text_list([]) | ||
'' | ||
>>> get_text_list(['a', 'b'], wrap_item_with="`") | ||
'`a` and `b`' | ||
""" | ||
if len(list_) == 0: | ||
return '' | ||
if wrap_item_with: | ||
list_ = ['%s%s%s' % (wrap_item_with, item, wrap_item_with) for | ||
item in list_] | ||
if len(list_) == 1: | ||
return list_[0] | ||
return '%s %s %s' % ( | ||
', '.join(i for i in list_[:-1]), | ||
last_word, list_[-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another quick comment on this line, please - something like "step backwards to a non-blank line". It just took me a minute to work it out.