#๐Ÿ”’ why the the function len giving me this answer

10 messages ยท Page 1 of 1 (latest)

pliant pond
#
        data[1].append(second)
        data[2].append('-' * len(second))
        data[3].append((' ' * max(len(data[0]), len(data[1]), len(data[2]))) + answer)

        print(data[2], len(data[2]))```



output
```858
['-----'] 1
948
['-----', '-----'] 2```<โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€” shouldnt the len() give me the number of โ€˜-โ€˜ in the output . so it shouldnt be 2 it should be the number o โ€˜-โ€˜ which in this case is  about 5
hexed blazeBOT
#

@pliant pond

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wary glade
#

It's printing the length of data[2], which currently has 2 items in it.

#

It doesn't care about the length of those items, just how many there are

#

If you wanted the length of one of the items in data[2] you'd get the length of data[2][0] or data[2][1] depending on wether you want the first or the second string

radiant aspen
#

len() depending on where is used, have different way of counting output; I'm assuming data[2] is a list with elements (where data itself is an another list and you have the ['-----'] list inside the data list

pliant pond
#

o ok ill try that thanks

#

it works thanks

hexed blazeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.