Is ternary iteration possible? A simplistic version of what I mean, though this particular example could be done in a better way:
c = 0
list1 = [4, 6, 7, 3, 4, 5, 3, 4]
c += 1 if 4 == i for i in list1 else 0
A more practical example:
strList = ['Ulis', 'Tolus', 'Utah', 'Ralf', 'Chair']
counter = 0
counter += 1 if True == i.startswith('U') for i in strList else 0
return counter
Your "practical example" is written as:
>>> strList = ['Ulis', 'Tolus', 'Utah', 'Ralf', 'Chair']
>>> sum(1 for el in strList if el.startswith('U'))
2
Your other example (if I understand correctly) is:
>>> list1 = [4, 6, 7, 3, 4, 5, 3, 4]
>>> list1.count(4)
3
(or just adapt the strList
example, but nothing wrong with using builtin methods)