0

I am trying to create pipeline that converts a number to its Ones' complement number, for example (8)

1234 -> 7654

83743 -> 05145

I tried to create something in this style but I can't figure out how to build the pipeline correctly.

int(''.join((my_number(lambda y: 8-y, list(my_number)))))

Error

TypeError: 'int' object is not callable

Popo
  • 39
  • 7

2 Answers2

5

The following should work:

int(''.join([str(8-int(y)) for y in str(my_number)]))

Example:

my_number=1258437620

Output:

>>> int(''.join([str(8-int(y)) for y in str(my_number)]))

7630451268
IoaTzimas
  • 10,538
  • 2
  • 13
  • 30
0

Another way is to generate a number consisting of the digit 8 and of a length equal to that of the number to be converted:

for n in 1234, 83743, 1258437620:
    n_1s = int('8' * len(str(n))) - n
    print(f'{n} => {n_1s}')
1234 => 7654
83743 => 5145
1258437620 => 7630451268
mhawke
  • 84,695
  • 9
  • 117
  • 138