My first dataset

Steps of creation

List elements from catalog:

import os
import time
def get_files_details(directory):
    details = []
    for filename in os.listdir(directory):
        if filename.endswith(".txt"):
           filepath = os.path.join(directory, filename)
           file_size = os.path.getsize(filepath)
           file_modification = time.strftime('%H:%M:%S',
                               time.gmtime(
                                   os.path.getatime(filepath)
                               ))
           details.append([filename, file_size, file_modification])
    return details

directory = r"C:\Users\Agnieszka\Desktop\FILE"
details = get_files_details(directory)

If we want to list songs or videos we have to install mutagen lib:

from mutagen.mp4 import MP4  #pip install mutagen

for images we will use Pillow lib:

from PIL import Image  #pip install Pillow

#Enter the music catalog to get songs names

import os
from mutagen.mp4 import MP4  #pip install mutagen
import time

#SELECTING FILES FROM ONE CATALOG:
def get_music_files_details(directory):
    details = []
    for filename in os.listdir(directory):
        if filename.endswith(".mp4"):
           filepath = os.path.join(directory, filename)
           file_size = os.path.getsize(filepath)
           audio = MP4(filepath)
           duration = time.strftime('%H:%M:%S',
                                    time.gmtime(audio.info.length))
           details.append([filename, file_size, duration])
    return details

directory = r"C:\Desktop\MUSIC\BAND_NAME\ALBUM"
details = get_music_files_details(directory)

print(details)

#Enter the music catalog and read: band names, album names and songs names

import os
import pandas as pd
from mutagen.mp4 import MP4  #pip install mutagen
import time

def get_music_files_details(directory):
    details = []

    #LIST OF FOLDERS (BAND NAMES) IN THE SPECIFIED PATH (X:\MUSIC)
    for catalog_name in os.listdir(directory):
        catalog_path = os.path.join(directory, catalog_name)
        #details.append(catalog_name)

    #LIST OF ALBUMS FROM EACH SUBFOLDER W (X:\MUSIC):
        if os.path.isdir(catalog_path):
            for subcatalog_name in os.listdir(catalog_path):
                subcatalog_path = os.path.join(catalog_path,
                                               subcatalog_name)
                #details.append([catalog_name,subcatalog_name])
    #SONGS LIST
                if os.path.isdir(subcatalog_path):
                    for filename in os.listdir(subcatalog_path):
                        if filename.endswith(".mp4"):
                           filepath = os.path.join(subcatalog_path,
                                                   filename)
                           #MB size calculation
                           file_size = round(
                               (os.path.getsize(filepath)/1048576),2)
                           audio = MP4(filepath)
                           #song duration
                           duration = time.strftime('%H:%M:%S', 
                                                    time.gmtime(audio.info.length))
                           #get song name from filename '1 Band Name - Song Name.mp4':
                           song_name = (
                               filename.split(' - ')[-1].rsplit('.', 1))[0]
                           #lista koncowa:
                           details.append([catalog_name, subcatalog_name,song_name, 
                                           file_size,duration])
    return details

directory = r"X:\MUSIC"
print(get_music_files_details(directory))

Export as TXT and an Excel file

def main():
    directory = r"X:\MUSIC"  
    details = get_music_files_details(directory)

    # DataFrame
    df = pd.DataFrame(details, 
                      columns=["Band", "Album", "Song",
                               "File Size (MB)", "Duration"])

    # Excel
    excel_file = "music_files_details.xlsx"
    df.to_excel(excel_file, index=False)
    print(f"The details of the music files "
          f"have been saved in "
          f"{excel_file}")

    # TXT
    text_file = "music_files_details.txt"
    df.to_csv(text_file, index=False, sep='\t')
    print(f"The details of the music files "
          f"have been saved in"
          f" {text_file}")


if __name__ == "__main__":
    main()

Loops for lists, tuples, dicts

Tpl = (1,8,2,4,3,5,7,6,9,0)
Lst = [1,2,2,3,3,3,1.1,2.1,3.1]
Dct1 = dict(name = "Aga", age = 35, year = 1989, hobby = "dance")
Dct2 = {'zodiac': "Cancer",'hair': "brown",'sex': "woman"}

for x in Tpl:
    print(x)
for x in sorted(Lst):
    print(x)
for item in Dct1:
    print(item)
for val in Dct1.values(): 
    print(val)

#Tuples

def calcs(a,b,c):
    return a+b, a**a, b/a, b**c
print(calcs(1,2,3))

names = ("Peter", "Cassandra", "April")
ages = (22, 47, 89)
for name, age in zip(names,ages):
    print(f"{name} is {age} years old")

t_array = ((1,2),(3,4),(5,6))

for in_tuple in t_array:
    for item in in_tuple:
        print(item, end = "::")
    print()

even_numbers = sorted(tuple(num for num in Tpl if num % 2 == 0))
squared_numbers = tuple(num ** 2 for num in Tpl)
print(even_numbers)
print(squared_numbers)

# A dictionary with tuple keys
points = {
    (1, 2): 'low',
    (3, 4): 'medium',
    (5, 6): 'high'
}

# Iterate through the dictionary items
for coordinates, label in points.items():
    print(f"Point {coordinates} is a {label} score")

#Dictionaries and lists


Lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Dictionary to hold even and odd numbers
categorized_numbers = {"even": [], "odd": []}

# Loop through each number in the list
for number in Lst:
    # Check if the number is even
    if number % 2 == 0:
        categorized_numbers["even"].append(number)
    else:
        categorized_numbers["odd"].append(number)

# Print the categorized numbers
print(categorized_numbers)

#Calculates the average grade for each worker

workers = {
    "Peter": [5, 4, 5],
    "Cassandra": [3, 4, 4],
    "April": [2, 1, 3]
}

# Dictionary to hold the average grades and pass/fail status
workers_score = {}

# Loop through each student in the dictionary
for student, grades in workers.items():
    # Calculate the average grade
    average_grade = round((sum(grades) / len(grades)),2)

    # Determine if the student passed
    if average_grade >= 3.5:
        status = "Passed"
    else:
        status = "Failed"

    # Store the result in the dictionary
    workers_score[student] = {"average": average_grade, \
                              "status": status}

# Print the student results
print(workers_score)

#Example from AI – manages an inventory of items

inventory = {
    "apples": 10,
    "bananas": 5,
    "oranges": 8
}

sales = {
    "apples": 4,
    "oranges": 2
}

restocks = {
    "bananas": 10,
    "oranges": 5
}

# Update inventory based on sales
for item, quantity_sold in sales.items():
    if item in inventory:
        inventory[item] -= quantity_sold

# Update inventory based on restocks
for item, quantity_restocked in restocks.items():
    if item in inventory:
        inventory[item] += quantity_restocked
    else:
        inventory[item] = quantity_restocked

# Print the updated inventory
print(inventory)