I'm a Python beginner. I have a question!

Asked 2 years ago, Updated 2 years ago, 15 views

I'm a Python beginner who has chosen to lay the foundation by learning example codes, etc. necessary for job application.

(In terms of piano, you don't learn the basics, but you just memorize one song you want to play.)

What I'm curious about is that I want to extract only rows with the value of '3' from Table A above.

There are conditions. I just want to pick "2 followed by 3."

As for the table, it's lines 5-10-19.

In this way, I want to extract only the data values that come under certain conditions (or next)

I don't know what command to get help from, so I'm asking for help like this!

python

2022-09-21 20:53

1 Answers

# If the table is given this way,
table_data = [{'A': 3}, {'A': 3}, {'A': 2}, {'A': 2}, {'A': 3}, {'A': 2}]

# You just have to go around for once like this.
for x in range(len(table_data)) :
    # There's an x-1th element, so if A of that element is 2 and the xth element is 3,
    if x - 1 >= 0 and table_data[x]['A'] is 3 and table_data[x-1]['A'] is 2 :
        # Use x.
        print('#' + str(x + 1) + ' => ', str(table_data[x]))


2022-09-21 20:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.