Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

FreePascal_PyCollections

View on Codeberg

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

PyCollections – Python‑style Collections for Free Pascal

PyCollections gives you Python‑like data structures in Free Pascal – dynamic lists, dictionaries, sets, and immutable versions.
Write cleaner, more expressive code without reinventing the wheel.


✨ Features

  • TPyList – dynamic array: append, insert, pop, sort (Timsort), reverse, slice, filter
  • TPyDict – hash‑based dictionary: get, setdefault, pop, keys/values/items
  • TPySet – unordered set with union, intersection, difference, subset tests
  • TPyOrderedSet – set that remembers insertion order
  • TPyFrozenSet – immutable, hashable set
  • TPyFrozenList – immutable list (tuple‑like)
  • TPyOrderedDict – dict that preserves insertion order
  • TPyFrozenDict – immutable, hashable dict

All collections work with for … in loops.


🚀 Simple Example

pascal
program Contacts;

uses PyCollections;

var
  names: TPyList;
  scores: TPyDict;
begin
  // Create a list and a dictionary
  names  := list(['Alice', 'Bob', 'Charlie']);
  scores := dict(['Alice', 95, 'Bob', 87, 'Charlie', 92]);

  WriteLn('Names: ', names.ToString);
  WriteLn('Scores: ', scores.ToString);

  // Add a new person
  names.Append('Diana');
  scores['Diana'] := 98;

  WriteLn('Updated names: ', names.ToString);
  WriteLn('Bob''s score: ', scores['Bob']);

  // Clean up
  names.Free;
  scores.Free;
end.