D in "for d in test_data:"

I have missed something or forget. I am unsure what the letter s meant in the loop and after looking at the answer I was don’t know what the letter d meant. s for string or the bad extra character? d no idea.

stripped_test_data = []
for d in test_data:
    date = strip_characters(d)
    stripped_test_data.append(date)

Could someone please clarify?

@petoorstanya

Hey, letter d does not have any specific meaning, you can use any letter you want.

It represents an item of a list.

For example,

test_data = [1,2,3,4,5]

then for the first pass of a loop
d=1
then
d=2
and so on…

Hope it clarifies your question.

2 Likes

for d in test_data means you are iterating through each element of test_data and as you iterate the current element of the test_data is stored in d.

for example if test_data is defined as below

test_data = [1,2,3,4,5]
for d in test_data:
print(d)

The output is
1
2
3
4
5

you could very well have used some other name for the element

test_data = [1,2,3,4,5]
for blahblah in test_data:
print(blahblah)

The output is
1
2
3
4
5

I hope that answers your question

1 Like