l = ["1", "2", "1", "1"]
for i in l:
if i == "1":
i = "3"
print(l)
Why is the result of l still ["1percent," 2percent, "1percent," 1"], and how can it be modified to ["3percent," 2percent, "3percent," 3"]?
l = ["1", "2", "1", "1"]
for i in l:
if i == "1":
i = "3"
print(l)
Why is the result of l still ["1percent," 2percent, "1percent," 1"], and how can it be modified to ["3percent," 2percent, "3percent," 3"]?
l = ['1percent,' 2percent, '1percent,' 1']
new_l = []
for i in l:
if i == '1':
new_l.append(3)
else:
new_l.append(i)
l = new_l
print (l)
-sharp
for i in range(len(l)):
if l[i] == '1':
l[i] = '3'
-sharp
for i, item in enumerate(l):
if item == '1':
l[i] = '3'
in addition, if you want to delete an element, it is recommended not to make changes directly on the original data. It is prudent to make a copy list.remove (value)
to delete.
-sharp
for idx, i in enumerate(l):
if i == '1':
l[idx] = '3'
-sharp
l = ['3' if i=='1' else i for i in l]
the newly installed win7 system, Ann python is, the installation package setup comes out of this, which I have encountered before. I forgot how to solve it. ...
the official WeChat of the school has an one-click function to check grades, and I have always wanted to be able to do it. Now I am learning python, and I am going to use it to practice, but I made a 500th error during the interview. here is the code:...
there are two built-in functions that have very similar functional descriptions: >>> help(exec) Help on built-in function exec in module builtins: exec(source, globals=None, locals=None, ) Execute the given source in the context of globa...
use the requests proxy module and do not change the ip address after success < hr > Code: import requests from bs4 import BeautifulSoup url=r http: ip.chinaz.com proxy={ http : http: 177.130.55.164:20183 , https : https: 177.1...
We know that the collections of the python built-in module has a lot of useful operations. for example: from collections import Counter -sharp -sharp top n user_counter = Counter("abbafafpskaag") print(user_counter.most_common(3)) -sharp[( ...
error "Invalid argument " is reported when there is an English question mark in the path of the parameter file when using the open function of python asked on stackoverflow, and a boss told me, "Install linux.. " Or something else that isn t Windo...
there is a problem with the configuration of fabric automated deployment! I hope you can take the time to answer! ( ) this is the code python -sharp! usr bin env python -sharp -*- coding: utf-8 -*- -sharp fabfile.py import os, re from datetime i...
The code structure of the project is as follows: main.py is the main program, and the method in file01.py under module is introduced, but because the method in file02.py is also introduced in file01.py, the method of file02.py will not be found during ...
I display such an error after executing according to the following code. class Game (object): top_score = 0 @staticmethod def __init__(self, player_name): self.player_name = player_name @staticmethod def show_help(): print(":") @...
problem description Fields of the database: uid, year, quarter, score 1 2018 4 1 2018 3 1 2018 3 2 2017 5 credits are counted on a quarterly basis, so points for a quarter need to be summed up. ...
A novice learner python, would like to ask about the use of the pass statement here. the last one below is an example on Mr. Liao Xuefeng s website. what is the purpose of the pass statement? Deleting pass and leaving pass seems to have no effect on t...
I can insert data into the mysql database with this command insert into moderation_task(id, media_id, user_id, media_url_or_path, media_title, media_source, created, updated, status, is_del) values(105, 75, 1, audit_source origin...
< H2 > question < H2 > Python s module socket uses ecv () to constantly listen to the request data sent by the client, including the empty string bounded . How to identify the empty request and block it? < H2 > Source code < H2 > Server side:...
Hello, I want to use multiprocessing to operate on a file, but it didn t achieve the desired results. The code is as follows. After the file stream is passed in, the child process does not run, and there is no printout. How to solve this problem? < hr...
there are hundreds of files. But none of them are big, and the largest ones are only a few megabytes . I use pycurl to download. I put the download address on the list. take out the first download, wait for it, and then take the second one. but t...
tgcode ="dafafadfaf" result = "window.config = %s ;" % (tgcode) print(result) f.write(result, ) python window.config = dafafadfaf ; window.config = dafafadfaf ; " , def modify_text_folder(tgcode): CONFI...
is that the A function uses the decorator, and the variable var inside the A function is passed to the decorator, and then it is checked and so on, okay? ...
problem description I have configured the mail server in config.yml mail.backend: smtp -sharp Use dummy if you want to disable email entirely mail.host: smtp.exmail.qq.com mail.port: 587 mail.username: mail.password: mail.use-tls: ...
topic description Mathematical Combinatorial problems sources of topics and their own ideas competitive programs what result do you expect? What is the error message actually seen? I tried a way to solve this problem in O (n). But get the wron...
sqlalchemy operation data Times error: Warning: (1292, "Truncated incorrect DOUBLE value: weixincode ") result = self._query(query) but the data is inserted. Why? the source code is as follows: @staticmethod def create_account(area_c...