How do I subtract 11 from a list and mod 121 the same list all at once?

给你一囗甜甜゛ 提交于 2019-12-25 21:24:10

问题


This is for prime number theory. This theory which actually shows up as an axiom factors numbers like 2^n-1 where n=11 or n=23 or n=29. Of course it would not factor n=7 or n=31 when those are Mersenne prime numbers.

Hopefully I can get help here I wish to do this all at once. I have this list below. I want to -11 from the entire list and then in the next instance mod 121 the list right after the subtraction while maintaining the enumerated list at the same time. Can this be done?

I'm getting this error:

print([x % 121 for x in lst1])
TypeError: not all arguments converted during string formatting

Here is part of the list and the code I have:

lst1 = [20, '231', 21, '243', 22, '247', 23, '253', 24, '259']
([int(i)-11 if isinstance(i, str) else i for i in lst1])
print([x % 121 for x in lst1])

回答1:


Here's a solution:


lst1 = [20, '231', 21, '243', 22, '247', 23, '253', 24, '259']
print([(int(item)-11)%121 for item in lst1])



来源:https://stackoverflow.com/questions/58868162/how-do-i-subtract-11-from-a-list-and-mod-121-the-same-list-all-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!