Elegant python and elegant python

Source: Internet
Author: User

Elegant python and elegant python

Based on the question, we cannot use keywords such as if/else/for/while.


-------------- Thinking ------------


Ideas:

1. Implement loops using recursion

2. How can we judge the recursive termination condition without the use of if? The answer is the dictionary, where not n is used to convert the number n to bool.


Code:

def sum_(n):    return n + {            True:lambda:sum_(n-1),            False:lambda:0        }[not not n]()print sum_(100)




What is the current prospect of python?

Nowadays, many companies require that, in addition to a static language, they can master a scripting language such as perl, shell, and python.
Because you often need to use the scripting language to develop some small programs at work, the reason is that the syntax of the script language is simple, so that programmers can quickly solve the problem.
Python can be used for development and management scripts.
Douban.com is developed in python.
As for the python salary, it is hard to say it depends on your company's situation.

Python for Loop

Wrong reading of the question. I will try again
============
Run python 3.2,> 3.0
Import functools
Def occurrences (text1, text2 ):
# Use a dictionary to count the number of text1 contained in text2.
S_items = dict (map (lambda I :( I [0], text2.count (I [0]), dict (zip (text1, [0] * len (text1 ))). items ()))
Print (s_items) # The output process is your "1 'E', 3 'l', 2 'o', and 1 'D'". This line can be deleted.
# Sum of combined output statistics
Return functools. reduce (lambda x, y: x + y, s_items.values ())
Print (occurrences ('fooed', 'Hello World '))
============================
Output
{'F': 0, 'E': 1, 'D': 1, 'O': 2, 'L': 3}
7

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.