Answers for "iterate through object in python"

24

python loop through dictionary

dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
for key, value in dictionary.items():
	print(key)
	print(value)
Posted by: Guest on July-02-2020
4

loop through python object

for attr, value in k.__dict__.items():
        print(attr, value)
Posted by: Guest on February-29-2020
0

iterate through objects with python

class C:
    a = 5
    b = [1,2,3]
    def foobar():
        b = "hi"    

for attr, value in C.__dict__.iteritems():
    print "Attribute: " + str(attr or "")
    print "Value: " + str(value or "")
Posted by: Guest on August-16-2020

Code answers related to "iterate through object in python"

Python Answers by Framework

Browse Popular Code Answers by Language