- 3
How can I count length of each item in a list
Counting letter of word
3 Antworten
+ 3
Mention the language as well. Though i'm assuming you're asking this in Python.
You can do this by creating a loop and targeting each value.
a = ['hello','hi','bye']
for i in range(len(a)):
print(len(a[i]))
+ 3
It's better to avoid using range(len()) thing unless you need to work with indices of a sequence.
for i in a:
print(len(i))
List comprehension
length = [len(i) for i in a]
+ 1
If it's in JavaScript just loop through it and check the length
var x=["ego","chigozie","money"]
for (var i = 0; i < x.length; i++) {
console.log(x[i].length)
}