Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9212649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:34:25+00:00 2026-06-18T01:34:25+00:00

So I’m writing a python script that will clean file names of useless and

  • 0

So I’m writing a python script that will clean file names of useless and unwanted characters, but I’m running into a problem, I can’t seem to figure out how to return a list or dictionary with all of the items in it that I iterated over. it only returns the first item I iterated over. this is my first time writing in python. any help would be greatly appreciated. I’m mostly writing this to learn. the clean_title() method is the one I’m trying to return from. and I call it at the bottom.

import os
import re

# here is how all my video files will look after this
# show name Season 1 Episode 1

filename = os.listdir("E:/Videos/TV/tv-show")



def clean_title(filename):
    name = {}
    for title in filename:
        n_title = title.split('.')
        index = [i for i, item in enumerate(n_title) if re.search('\w\d{2}\w\d{2}', item)]
        if len(index) > 0:
            name = {'title':n_title[0:index[0]], 'ep_info':n_title[index[0]]}
            return name


def get_show_name(filename):
    pass


def update_title():
    #show_title = get_show_name + ' ' + get_episode_info
    #print show_title


if __name__=="__main__":
    test = clean_title(filename)
    print test
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:34:26+00:00Added an answer on June 18, 2026 at 1:34 am

    You have two distinct problems.

    The first is that you’re returning from inside your loop, so you will only have processed a single iteration of the loop when you hit the return statement. That’s why it looks like you’re getting the first iterated value when, in fact, you’re never reaching the other iterations.

    You can fix this by out-denting the return statement to the correct level.

    The second problem is in the way you’re accruing your results to return from clean_title(). You are only ever storing a single cleaned title in the name variable. Each time through the loop you’re overwriting the previously calculated title with the new one from that iteration. Even if you fix the return issue, the current version would then return the last title you computed.

    You can accrue your results in either a list or a dictionary. If a list, you initialize with name = [] and add new titles with name.append(title_goes_here). If you want to accrue your results in a dictionary, you initialize with name = {} and add new titles with name[index_goes_here] = title_goes_here. Note that in the case of a dictionary you need to have some logical key value (usually an integer or string) that you will use to recover the value later on.

    Finally, I have to add that I find your use of singular case (filename, title, clean_title) for plural objects and actions to be confusing. I’d call a list of file names filenames, and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need to clean up various Word 'smart' characters in user input, including but
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.