List examples
These examples grow a report sequence, read by position, insert into the middle, remove an item, and iterate over the remaining values.
Python
import json
def print_label_value(label, value):
print(f"\033[1;36m{label}:\033[0m {value}")
def json_value(value):
return json.dumps(value, separators=(",", ":"))
reports = ["login issue", "reward missing"]
print_label_value("1. Initial reports", json_value(reports))
reports.append("account locked")
print_label_value("2. Add report", json_value(reports))
print_label_value("3. Read report 2", reports[1])
reports.insert(1, "matchmaking down")
print_label_value("4. Insert report 2", json_value(reports))
removed_report = reports.pop(2)
print_label_value("5. Remove report 3", removed_report)
print_label_value("6. Remaining reports", json_value(reports))
print_label_value("7. Iterate reports", " | ".join(reports))
JavaScript
function printLabelValue(label, value) {
console.log(`\x1b[1;36m${label}:\x1b[0m`, value);
}
const reports = ["login issue", "reward missing"];
printLabelValue("1. Initial reports", JSON.stringify(reports));
reports.push("account locked");
printLabelValue("2. Add report", JSON.stringify(reports));
printLabelValue("3. Read report 2", reports[1]);
reports.splice(1, 0, "matchmaking down");
printLabelValue("4. Insert report 2", JSON.stringify(reports));
const removedReport = reports.splice(2, 1)[0];
printLabelValue("5. Remove report 3", removedReport);
printLabelValue("6. Remaining reports", JSON.stringify(reports));
printLabelValue("7. Iterate reports", reports.join(" | "));
Expected output
1. Initial reports: ["login issue","reward missing"]
2. Add report: ["login issue","reward missing","account locked"]
3. Read report 2: reward missing
4. Insert report 2: ["login issue","matchmaking down","reward missing","account locked"]
5. Remove report 3: reward missing
6. Remaining reports: ["login issue","matchmaking down","account locked"]
7. Iterate reports: login issue | matchmaking down | account locked