0

I want to learn how to automatically provide enough | operators between each of the indexes from this a list. I understand that I cannot do '|'.join(a) since the contents arent strings.

from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow
from PyQt6.QtCore import Qt
import sys

class NewLabel(QLabel):
    def __init__(
        self,
        place,
        center=False,
        left=False,
        right=False,
        top=False,
        bottom=False,
        **kwargs,
        ):
        super().__init__(place, **kwargs)
        cycle = (center, 0x0080), (center, 0x0004), (left, 0x0001), (right, 0x0002), (top, 0x0020), (bottom, 0x0040)
        a = [Qt.AlignmentFlag(x[1]) for x in cycle if x[0]] or [Qt.AlignmentFlag(0x0001)]

        self.setAlignment(a[0]|a[1]|a[2] if len(a) > 2 else a[0]|a[1] if len(a) > 1 else a[0]) # <-- how can I improve this row

class Main(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.label = NewLabel(self, text='some string', center=True, right=True)
        [x.resize(200,100) for x in (self, self.label)]
        self.show()

if '__main__' in __name__:
    app = QApplication(sys.argv)
    window = Main()
    app.exec()
ILS
  • 1,224
  • 1
  • 8
  • 14
Plutonergy
  • 39
  • 1
  • 3
  • 1
    `functools.reduce(operator.or_, a[:3])` – Mechanic Pig Oct 04 '22 at 08:56
  • Does this answer your question? [How to use filter, map, and reduce in Python 3](https://stackoverflow.com/questions/13638898/how-to-use-filter-map-and-reduce-in-python-3) – ILS Oct 04 '22 at 09:03

0 Answers0