0
for case in log:
    for event in case:
        if event in process_model:
            index = process_model.index(event)
        else: print(event, index)
---------- output-----------
NameError: name 'index' is not defined

I still need to use index

2
  • 5
    I don't understand. What would index be in the case that if event in process_model is False? You can give it a default value before if event in process_model but I'm not sure how that fits with "I still need to use index" Commented Apr 8, 2018 at 15:22
  • I need to use the value of index when the event not in process_model . The problem is handling if-statement scop. – Commented Apr 9, 2018 at 1:40

1 Answer 1

1

Is this what you're looking for?

for case in log:
    for event in case:
        if event in process_model:
            index = process_model.index(event)
        else:
            index = None
        print(event, index)

Or (if case has a __repr__ method and you want to be well informed):

for case in log:
    for event in case:
        if event in process_model:
            index = process_model.index(event)
        else:
            index = None
        print(case, event, index)
Sign up to request clarification or add additional context in comments.

2 Comments

I need the value of index when the event not in process_model . The problem is handling if-statement scop.
If event isn't in process_model, index won't have a value, since index indicates the location of event in process_model, which it then doesn't have. That's why it's assigned None. It's like asking for the house number of a house that isn't in a street. It simply doesn't have one. Probably you know what you want, but unfortunately I do not understand what exactly it is...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.