Learn a little Python every day

Source: Internet
Author: User

September 11

1. Use List to implement? : Conditional expression

["False", "true"] [judgment condition]

It is actually a problem of List [0] or List [1. If the condition is true, it is List [1]. If the condition is not true, It is List [0.

2. Write a bubble sort in Python

 j =1         i  range(len(List)-j-1(List[i+1]>+1]=List[i+1=     List

I am very interested today. I want to learn more.

3. Output a string in reverse order

word1== i +=word[-1-(word2)

Simpler Method

(word[::-1])

Essence: the first parameter is the start position, the second parameter is the length, and the third parameter is the step field. If the third parameter is set to a negative number, the start point is backward. List can also be used in reverse order.

September 12

1. Output all keys in a dictionary, separated by commas.

result= k,v +=k+(result[:len(result)-1])

I didn't expect a better method to remove the last "," so I had.

2. Read a txt file

file1=open(=file1.readlines(100 line (line)

3. output the prime number and number of equal to 100

The idea at the beginning was to determine whether 2 to n ** 1/2 numbers could be divisible, and the code would not be written, similar to the C language.

I want to use a List partition that is unique in Python. The Code is as follows:

=[i  i == j  range(2 j  +=list1[j::j][1 [list2,list3]

List1 contains all numbers ranging from 0 to. Put the prime number in List3, put its multiples in List2, and finally separate them. However, it should be less efficient.

I found the List Subtraction Method carefully and wrote a new method after dinner.

September 13

1. output the prime number and number of equal to 100 (continued)

Next, it was raining heavily yesterday. Finally, we found that the so-called List subtraction method is to convert the List to set subtraction and then back to the List.

So use set directly. Use union and difference of set. The Code is as follows:

= {I range (2, num)}/* The prime number is stored here */= set () /* Number of stored shares */j = set2 | {I range (j ** 2/**/= set1-/**/[set1, set2]

A problem was found in the middle. set2 = {} generates a dict and can only use set2 = set () to create an empty set. range (starting value, final value, step size) is used) generate a collection and deduplicate the set. There should be a better way.

September 16

I haven't updated it in two days. I learned some Python object-oriented basics in these two days, but the project is too busy and I didn't want to use any examples to show what I learned .. . I want to write a simple workshop model, but it is not successful. After that, let's make up the knowledge.

I visited the school website last night and found that the website for physical testing had an injection vulnerability. after a long time of exploration, I injected the website and exported a lot of data from my classmates... What are you planning to do with python and the data.

The current plan is to first learn python to process analysis files, extract the data in the html, and separate the data by region. Then, learn the python web application and make a web page for querying fellow students.

Due to time, the progress may be slow, but try to stick to the update progress to the blog.

Related Article

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.