Question: How can you get the position number of a particular PyQt-widget in a list? 

I am trying to implement something like 

```
self.Reg_Labels =[] # list fot QLabel
self.Reg_Fields =[] # list for QLineEdit

for i in xrange(53):
    x = str(self.Registers(i)) 
    self.Reg_Labels.append(QtGui.QLabel(x)) # this gets a label text in every iteration 
    self.Reg_fields.append(QtGui.QLineEdit()) 

for y in xrange(53):
    self.Reg_Fields[i].returnPressed.connect(lambda : self.reg_change(y)
    # i  also want to send the position of the QLineEdit in the list 
    # but i always get the last position for any change in QLineEdit 
.
.
def reg_change(self,num):
    sender = self.sender()
    print num, sender.text() ,sender.objectName()

```

I want to get the text of the `QLabel` at the same position as the changed `QLineEdit` widget.

F.ex. if the 30th `QLineEdit` widget text is changed I want to pass the text of the 30th `QLabel` from the `self.Reg_Labels` list.

Answer: 
Changing `lambda : self.reg_change(y)` to `lambda y=y: self.reg_change(y)` should call `reg_change` with the right `n`, so in there you can than try `sender = self.Reg_fields[n]`.

Or just pass the element of `Reg_fields` right away:

```
for field in self.Reg_Fields:
    field.returnPressed.connect(lambda field=field: self.reg_change(field))

def reg_change(self, field):
    print field.text(), field.objectName()

```
While [@causa prima's answer](https://stackoverflow.com/users/1065901/causa-prima) seems to have solved you problem, using a dictionary might improve the readability of your code 

You could replace 

```
self.Reg_Labels =[] # list fot QLabel
self.Reg_Fields =[] # list for QLineEdit

```

with

```
self.Reg = {}

```

as a dictionary from QLineEdit to QLabel, insert via

```
for x in [str(reg) for reg in Registers]:
    self.Reg[QtGui.QLineEdit()] = QtGui.QLabel(x) # this gets a label text in every iteration 

```

(assuming `Registers` is an iterable, you can use this form, else just use the `xrange`).