0

I have this code so far

data = ['fx_name_v002.1001.exr  fx_name_v002.1016.exr', 'fx_name_v002.1002.exr  fx_name_v002.1018.exr']
 data.sort()

frames = []

def string_split(data):
    for i in data:
        print(i.split('.'))

I need to split the list like I have. Once the list is split I need to add the 1002, 1001, of the split ends into the empty list frames.

The end result should be frames = ['1001', '1002', 'etc']

The part im confused on is the loop and after i split the list how to append the 1001, 1002, etc into the empty frames list.

Edit 1: Solved

Edit 2: So now I've been trying to reverse engineer regex and do research. How would I get the first part of the string, everything before 1001, 1002, etc. into a different list?

4
  • What about 1016 and 1018? Commented Jun 27, 2018 at 20:04
  • Exactly which step are you stuck on? Commented Jun 27, 2018 at 20:04
  • im stuck on how to transfer the certain part of the split 1001, 1002, etc into the empty list frames Commented Jun 27, 2018 at 20:05
  • What exactly do you need to do ? What result are you supposing to get with the arguments you gave ? What are you trying to do and where is your problem ? Commented Jun 27, 2018 at 20:06

2 Answers 2

1

You can do this pretty easily with regex!

import re

pattern = r'.(\d{4}).exr'
frames = re.findall(pattern, ' '.join(data))
print(frames)
# ['1001', '1016', '1002', '1018']
Sign up to request clarification or add additional context in comments.

4 Comments

This works fine but only outputs 1001, i'd need to get 1002 and the rest
Really? Mine output all four of them in a list. Are you sure you're using re.findall?
Have you run either answer? You have put this exact comment on both answers, and this one runs fine for me
Okay, I got it to work, I had some conflicting code that messed with the output. Thank you for your help!
0

If you are just trying to get the numbers from the first file arg in each element

for i in data:
    var = i.split()[0]
    frames.append(var.split('.')[1])

Comments

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.