Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python programming task #3 #299

Closed
activus-d opened this issue Feb 6, 2023 · 1 comment
Closed

Python programming task #3 #299

activus-d opened this issue Feb 6, 2023 · 1 comment

Comments

@activus-d
Copy link

Based upon programming task #1 – Given a list of locales (["en", "is", "en_GB"]), and a list of versions (["latest", "4.1.x", "4.2.x"]), generate a CSV file ready to import with Wagtail’s bulk redirects importer.

locales = ["en", "is", "en_GB"]
versions = ["latest", "4.1.x", "4.2.x"]

def generate_combinations():
    return ["en-latest", "en-4.1.x", "is-latest", "is-4.1.x"]


def create_csv():
    # Generate combinations, then create CSV file based on them.
    pass

CSV file sample:

from,to
/en-4.0.x/,/
/en-4.1.x/,/
/is-4.0.x/,/
/is-4.1.x/,/

This helps practice:

  • Working with a specific file format (CSV)
  • Creating files with Python
  • Structuring larger programs
@activus-d
Copy link
Author

activus-d commented Feb 6, 2023

@Stormheg @thibaudcolas @allcaps kindly review my solution to this task:

import csv


locales = ["en", "is", "en_GB"]
versions = ["latest", "4.1.x", "4.2.x"]

def generate_combinations(locales, versions):
    combined_list = []
    for locale in locales:
        for version in versions:
            combined_list.append(f"{locale}-{version}")
    return combined_list

def create_csv():
    list = generate_combinations(locales, versions)
    with open("combinations.csv", 'w') as file:
        writer = csv.writer(file)
        return writer.writerow(list)

create_csv()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants