简体   繁体   中英

why join doesn't work on a list comprehension

','.join([number for number in range(2000,3201) if number%7 == 0 and number%5 != 0])

doesn't work.

However,

l=[]
for i in range(2000, 3201):
    if (i%7==0) and (i%5!=0):
        l.append(str(i))

','.join(l)

works. Aren't two things in the parenthesis of type list?

join expects string types, you will have to modify your list function like this:

','.join([str(number) for number in range(2000,3201) if number%7 == 0 and number%5 != 0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM