Python list is deleted while traversing it. How can I use it without reporting out of bounds error?

Sleeping devil's lies 2020-11-12 16:11:10
python list deleted traversing it.

IDEA Editing function

IDEA Powerful automatic code completion function shortcut key Tab, When the code tag is entered , Press Tab, The generated code .

  1. div.class.out + Tab
  2. Commonly used fori/sout/psvm+Tab You can generate a loop
  3. System.out、main Such method boilerplate Sample code , To input for(User user : users) Simply enter user.for+Tab
  4. Input for(User user : users) Simply enter user.for+Tab
  5. To input Date birthday = user.getBirthday(); Simply enter user.getBirthday().var+Tab that will do .

Python View the usage of a module in the

Python After the command line input , have access to help Methods view the usage of methods , for example :

import re
 Copy code 

Output the description information of the method in the console :  Insert picture description here

Python Don't ignore the first line

Python Handle csv When you file ,pandas.read_csv(“data.csv”) By default, the first line will be used as the header line information , Don't deal with it . How to get it to start with the first line ?header=None That can be achieved .

df = pd.read_csv("data.csv", header=None)
 Copy code 

The process of the object's promotion to the old age

Priority is given to Eden Distribute , And there are many situations for the new generation to be promoted to the old age (1)、Eden Area is full , Conduct Minor GC, When Eden And a Survivor Objects that are still alive in the zone cannot be put into Survivor in , Then it will be transferred to the elderly in advance through the distribution guarantee mechanism . (2)、 If the object is too large , The new generation cannot accommodate this object ,-XX:PretenureSizeThreshold That is, the size of the object is greater than this value , It will bypass the new generation , Distribute directly to the older generation , This parameter only applies to Serial And ParNew Two collectors work . (3)、 Long lived objects go directly into the old generation .

Python Delete while traversing

Deleting an array while traversing it will change the index range of the array , Cause program error , This is in Java It's also a problem that needs attention . however ,Python The method of data processing provides an ingenious processing method .  Insert picture description here Use sorted(list) , A new array will be generated , So delete the elements of the original array accordingly , It doesn't change the subscript , No mistakes . That is to say, in the process of traversing, we use sorted(list) New array returned , Delete is the operation of the original array , That is, the traversal uses a copy , After modifying the original data, we get the final result we need .

__name__ The meaning of

Often see Python Will see if __name__ == '__main__': This code , What does this code do , After removing this code , Why the program doesn't execute ?

__name__ It's a system built-in variable , Represents the name of the module , That is, the name of the file . When the module runs directly , Such as Files are run directly ,__name__ The value of is “__main__”, therefore if __name__ == '__main__': It usually triggers the main process .

The process of derivation

The process of derivation : It's to put the whole final result back into the container , Instead of traversing and deducing . After the derivation is executed , Write the result to tmp_list Variable , Instead of writing directly in the process of derivation tmp_list Variable .

tmp_list = [i for i in num_list if i not in tmp_list]
 Copy code 

It's invalid ,tmp_list It's not the expected derived value .

analysis ngix The log counts the number of lines by hour

Given a ngix Log files , Parse the time column and count the number of log lines per hour by time . The log file format is : [22/Oct/2019:23:58:54 +0800] "POST /dasdhj/sadqwda/q.log HTTP/1.1" 200 133 0.022 "-" "Apache-HttpClient/4.3.3 (java 1.5)" "-"
 Copy code 

To write Shell The parsing command is :

awk '{ print $2}' ngix.log | awk -F ":" '{a[$2]=a[$2]+1} END {for(i in a) { print "time:",i,"count:",a[i]}}'
 Copy code 

Ideas :

  1. First of all, the log is divided into spaces , Get the logging timestamp column of the second column
  2. Then divide the time column by colon , Get the time column , And add up in time series
  3. Output time and cumulative value

input Forms don't trigger onclick event

A simple trigger hides a h1 The event of the tag , But not implemented , The code is :

<h1 id="EleId"> Please click on this text !</h1>
<input type="button" value=" Click Hide " οnClick="alert('111');">
 Copy code 

Repeat the test , The final confirmation is input Wrong usage , Use button The button element is OK :

<button id="clear-button" onclick="clearInput();"> Click Hide </button>
 Copy code 

Thread pool shutdown causes AtomicInteger The count is not accurate

AtomicInteger Class is to use CAS Principle to implement atomic operations on numeric types , And concurrency is more efficient than synchronized Much higher . Today, I saw a thread pool shut down earlier , Lead to the task of AtomicInteger Count operation not performed , And then the printed count value is not accurate .

This problem side verifies the efficiency of atomic classes , Besides , Another knowledge point is about ConcurrentLinkedQueue Class , Determine if there are any elements in the queue , You should use isEmpty() , Instead of size(). Because it's a linked list ,size The operation needs to traverse the list to count the total number of elements ; and isEmpty() Direct judgment first Is it null , More efficient than the former .

ajax request 415 problem

SSM In the project ajax 415, It appears that the request type is json Backstage 415 The problem of , This is mainly about the file type and SpringMVC The configuration type is inconsistent :

  1. type:json
  2. The backstage should specify medias contain json type

author : Bi Xiaobao
本文为[Sleeping devil's lies]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database