Is Python the most advantageous in simplifying code?

Source: Internet
Author: User
For example, if you print the sum and most common condition that can be divisible by 2 and 3 in 1-101, you may write TheSum0forxinxrange (): ifx % 20 andx % 30: theSum + xprintTheSum: for example, the sum of sums and
The most common condition may be written in this way.

TheSum=0for x in xrange(101):    if x %2==0 and x%3==0:        TheSum+=xprint TheSum
Reply content: No

J

+/ (#~ (0=2&|) *. (0=3&|)) 1+i.100
Scala:
6 to 100 by 6 sum
Think about readability. sum (range (6,101, 6 ))

1 to(100) asList select(%6==0) sum
Haskell: sum [x | x <-[1 .. 100], x 'mod' 6 = 0]

sum [x | x <- [1..101], x `mod` 2 == 0 && x `mod` 3 == 0]
It can be divided by 2 and 3, not 6.
Sum [6, 12 .. 101] Ruby is also easy

(1..100).select{|x| x%6 == 0 }.inject(:+)
This kind of thing is more important than syntactic sugar and standard library... Sum [6, 12 .. 100]


Which of the following statements about Haskell... Let's write it like this...

Sum. filter (= 0). ('mod' 6) $[1 .. 100]


There are also those who have written [1 .. 100] as [0 .. 101! Have you reviewed any questions? I know how to play with it...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.