Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 列表附加条件_Python_List_Conditional - Fatal编程技术网

Python 列表附加条件

Python 列表附加条件,python,list,conditional,Python,List,Conditional,在这种特定情况下,我如何制作一个适当的if条件,只在列表中添加一个价格值,例如53以下的价格值 offers_list = re.findall("<div class=\"list\"(.*?)</div>", http_response_body, re.DOTALL) # Find list of offers in HTTP Response Body price_list = [] offers_list2 = [] for i in offers_list:

在这种特定情况下,我如何制作一个适当的if条件,只在列表中添加一个价格值,例如53以下的价格值

offers_list = re.findall("<div class=\"list\"(.*?)</div>", http_response_body, re.DOTALL) # Find list of offers in HTTP Response Body
price_list = []
offers_list2 = []

for i in offers_list:   # loop in the list of offers to look for the specific price values
    a = re.findall("\"price\"=(.*?)\"", i)  # Find specific price value within in each offer
    print a
    price_list.append(a) # Append to list only if the price is lower than X amount
    offers_list2.append(a)

但是
print a
for循环之外
显然只打印一个值,因为它只执行了一次搜索,而不是在所有的选项中执行循环。

假设您的正则表达式工作正常,这样做可能会:

for price  in a:
    if int(price)<=53:
        price_list.append(price)
        offers_list2.append(price)
适用于a中的价格:

如果是int(price),我认为询问者想要
<53
而不是
价格应该是浮动值,而不是int。对于货币金额
浮动
有多安全?参见PEP 327。可能是一份关于靓汤的工作。
for price  in a:
    if int(price)<=53:
        price_list.append(price)
        offers_list2.append(price)