[Python] Iterate over list of class objects - 'pythonic' way

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list test_cases with class objects. Every object has an attribute called ident. I want to iterate over all objects from list and do something with value under ident

    This is my code:

    class TestCase:
    def __init__(self, title, ident, description):
    self.title = title
    self.ident = ident
    self.description = description

    test_cases = []
    test_cases.append(TestCase(**tc_dict))

    i = 0
    while i != len(test_cases):
    print(test_cases.ident)
    i += 1


    It works fine, but what I want to ask, if there is a more 'pythonic' way to do that.

    Continue reading...

Compartilhe esta Página