how to append a group of number at different index in a list to another list

Question:

pls guys, I’m scrapping details from a real estate website and i want to get the number of bedrooms , bathroom and size of the house
but how the details are arrange is very difficult to separate.

Bedroom = []
Bathroom = []
Size of Building = []

houses = []
Hux_clean = []

details  =province_soup.find_all("li",class_="mr-3 flex items-center")
for detail in details:
    houses.append(detail.get_text())

for house in houses:
    Hux_clean.append(house.strip())
    
for value, count in enumerate(Hux_clean):
    print(value, count)
    if value==0:
        Bedroom.append(count)

output:

0 2
1 2
2 168 m²
3 3
4 2
5 110 m²
6 7
7 4
8 260 m²
9 4
10 4
11 334 m²
12 3
13 2
14 301 m²
15 3
16 2
17 106 m²
18 4
19 4
20 624 m²
21 2
22 1
23 60 m²
24 3
25 3
26 379 m²
27 3
28 3
29 323 m²
30 2
31 1
32 81 m²
33 3
34 2
35 122 m²
36 3
37 1
38 85 m²
39 5
40 4
41 473 m²
42 3
43 3
44 125 m²
45 5
46 5
47 377 m²
48 3
49 2
50 85 m²
51 4
52 4
53 965 m²
54 3
55 2
56 106 m²
57 2
58 2
59 85 m²

I want to append value at index 0, 3, 6, 9 etc to Bedroom

append value at index 1, 4, 7 etc to Bathroom

also append value at index 2, 5, 8 etc to size of Building

Asked By: Jimoh endurance

||

Answers:

Iterate through Hux_clean in steps of 3, and append the appropriate elements to each list.

for i in range(0, len(Hux_clean), 3):
    bedroom, bathroom, size = Hux_clean[i:i+3]
    Bedroom.append(bedroom)
    Bathroom.append(bathroom)
    Size_of_Building.append(size)
Answered By: Barmar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.