Ask Your Question
0

infinite if inside a loop

asked 2020-12-22 22:22:45 +0100

anonymous user

Anonymous

updated 2020-12-23 15:28:07 +0100

slelievre gravatar image

I want to define a function that checks if a member of a set is another then print "well".

Let me explain it it the following example:

Assume that Z = Compositions(17, min_part=4).list(), L is some set and f is some function.

How I can write a function such that if f(a), where a is a member of Z, was in L, then that is "well"?

My attempt:

for i in in srange(len(Z)):
    for j in srange(i):
       if f(Z[i][j]) in L:

I don't know how to finish it because I just know finite if, else, not more.

edit retag flag offensive close merge delete

Comments

Can you make your example a little more concrete by providing an actual L and f?

slelievre gravatar imageslelievre ( 2020-12-26 03:01:49 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-06 03:04:55 +0100

dan_fulea gravatar image

Do you want something like this... ?!

def f(a):
     return ZZ(a).is_prime()
L = [True]

# we search all partitions of 17 in pieces $\ge 4$, which are each prime
for z in Compositions(17, min_part=4):
    f_values = {f(a) for a in z}
    if f_values.issubset(L):
        print(f"{z} is well")

Results:

[17] is well
[7, 5, 5] is well
[5, 7, 5] is well
[5, 5, 7] is well
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-12-22 22:22:45 +0100

Seen: 234 times

Last updated: Jan 06 '21