Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

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

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])
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's a solution:


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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...