0 Replies - 502 Views - Last Post: 06 June 2018 - 08:43 AM

#1 bobsmith76   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 363
  • Joined: 14-February 17

The funniest code I ever wrote

Posted 06 June 2018 - 08:43 AM

Here was an instance where it was actually appropriate to use the words 'freeze children', 'frozen child', 'freeze grandchildren' and 'frozen grandchildren' in my code. What the code does is it forms a hierarchy of sets of sets. You can't put sets inside sets in python. Instead you have to turn them into frozensets first. So since I am forming a hierarchy I think it is best to call the ranks: parents, children and grandchildren. The children and the grandchildren are sets, so when I turn them into frozensets I think it's best to call them frozen children and the function that freezes them is called freeze children. The fs is a class which freezes the sets written by yours truly baavgai and I want to thank him again for helping me make frozensets legible because they are not currently legible the way Guido has written them. Maybe if the urge hits me I'll try to post an example of what the code does in that other forum where you can share your code.

lbr = chr (10647)
rbr = chr (10648)

class fs(frozenset):
    def __init__(self, *args, **kwargs):
        # frozenset.__init__(self, *args, **kwargs)
    def __str__(self):
        str1 = lbr + "{}" + rbr
        return str1.format(','.join(str(x) for x in self))

def freeze_sent_type(cls):
    embeds = set()
    for parent, value in cls.parents.items():
        if isinstance(value, set):
            parent_kind = cls.sent_kinds.get(parent)
            frozen_children = freeze_children(cls, value)
            if parent_kind != None:


    return embeds

def freeze_children(cls, value):
    frozen_children = set()
    for st in value:
        child_kind = cls.sent_kinds.get(st)
        child = cls.children.get(st)
        if isinstance(child, set):
            frozen_grandchildren = freeze_grandchildren(child, cls)
        if child_kind != None:

    return frozen_children

def freeze_grandchildren(child, cls):
    frozen_grandchildren = set()
    for sent_num in child:
        grand_child_kind = cls.sent_kinds.get(sent_num)
        grandchild = cls.grandchildren.get(sent_num)
        if grand_child_kind != None:

    return frozen_grandchildren

Is This A Good Question/Topic? 0
  • +

Page 1 of 1