Using 'max' and 'len' to properly format the 10th item of a list

using thesaurus
another word for using something
using someone synonym
useing or using
using meaning in hindi
using semicolons
using symbol
define utilize
    for i, items in enumerate(zip(member_names, scores)):
        if i < 10:
            if i == 9:
                msg += "{:<1}. {:<{names_len}} <{:,}>\n".format(i + 1, *items, names_len=len(max(member_names, key=len)) - 1)
                continue
            msg += "{:<1}. {:<{names_len}} <{:,}>\n".format(i + 1, *items, names_len=len(max(member_names, key=len)))

Here's an example output:

1. xxxx#1598         <12,704>
2. xxxxxxxxxxxx#2390 <7,151>
3. xxxxx#4966        <5,859>
4. xxxx#3562         <3,051>
5. xxxxxxx#6967      <2,831>
6. xxxxx#4643        <2,073>
7. xxxxx#2006        <1,833>
8. xxxx#4720         <1,679>
9. xxxx#8049         <1,651>
10. xxxxxxxxxxxx#8514 <1,614>

member_names is a list with a few dozen items in it. My two issues:

  1. I can't get it to properly account for the fact that the 10th item in the list will need one less space of indention.
  2. Being such, as you can see, the 10th item does not extend the indention an extra character while using names_len.

Can anyone help with this? I'm fairly new and have been stumped on this for quite a while.


I would try to unclutter the whole thing a bit. Let's find out the maximum length ahead of time (instead of having to determine it once per loop); same with the maximum index number:

num_items = len(str(len(member_names)))
max_length = len(max(member_names, key=len))
for i, items in enumerate(zip(member_names, scores)):
    msg += "{:>{n}}. {:<{m}} <{:,}>\n".format(i + 1, n=num_items, *items, m=max_length)

(I hope this works as is - can't test it without access to your data)

Use, describing an action or state of affairs that was done repeatedly or existed for a period in the past. Define using. using synonyms, using pronunciation, using translation, English dictionary definition of using. v. used , us·ing , us·es v. tr. 1. To put into service


You could simply ident the lower numbers by right-aligning them:

member_names = [f"name_{i}" for i in range(14)]
scores = [3**i for i in range(14)]

maxlen = len(max(member_names, key=len)) # calculate only once
msg = ""
for i, items in enumerate(zip(member_names, scores)):
    msg += "{:>2}. {:<{ml}} <{:,}>\n".format(i + 1, *items,ml=maxlen)

print(msg)

Output:

 1. name_0  <1>
 2. name_1  <3>
 3. name_2  <9>
 4. name_3  <27>
 5. name_4  <81>
 6. name_5  <243>
 7. name_6  <729>
 8. name_7  <2,187>
 9. name_8  <6,561>
10. name_9  <19,683>
11. name_10 <59,049>
12. name_11 <177,147>
13. name_12 <531,441>
14. name_13 <1,594,323>

See Tim Pietzckers answer for a more flexible approach that would allow >99 highscores and still be aligned.

"Used to" or "used for"?, be or become familiar with someone or something through experience. Using: to put into action or service. Synonyms: applying, employing, exercising… Find the right word. SINCE 1828. GAMES; BROWSE THESAURUS; WORD OF THE DAY; WORDS AT


len()already returns the number of items in a list. (documentation) max() returns the highest number. (documentation)

So len(max()) returns 1, as it looks for the highest number in the list (10) and then calls len(10), which == 1

Be used to, get used to, used to – Speakspeak, verb (used with object), used, us·ing. to employ for some purpose; put into service; make use of: to use a knife. to avail oneself of; apply to one's own purposes: to use the facilities. to expend or consume in use: We have used the money provided. Synonyms for using at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for using.


. utilize, make use of, avail oneself of, employ, work, operate, wield, ply, apply, manoeuvre, manipulate, put to use, put into service, find a use for, resort to. use, employ, utilize mean to put into service especially to attain an end. use implies availing oneself of something as a means or instrument to an end. willing to use any means to achieve her ends employ suggests the use of a person or thing that is available but idle, inactive, or disengaged.


of a person or thing that is available but idle, inactive, or disengaged. Definition of using : 1. verb (gerund form), to carry out a purpose, to make use of You shouldn’t be using your phone while driving! 2. noun, exercising sth, putting sth into action


to + verb infinitive refers to a habit or state in the past. The using statement ensures that Dispose is called even if an exception occurs within the using block. You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block; in fact, this is how the using statement is translated by the compiler. The code example earlier expands to the following