BeAllAround / BeAllAround/py_utils

credentials for the deepEqual python-native __utils library extension

Open
#9 2 comments 0 reactions 1 assignee Claimed by @BeAllAround View on GitHub
documentation enhancement
Dominant language
Python
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

```
# deepEqual - dicts
def __eq__(obj, _obj):
if type(obj) != type(_obj):
return False

if type(obj) == dict and type(_obj) == dict:
if len(obj.keys()) != len(_obj.keys()):
return False
for key in obj.keys():
if key not in _obj.keys():
return False
if(not __eq__(obj[key], _obj[key])):
return False
return True
else:
return obj == _obj

# tests

print('# test 1: ', __eq__({'a': 1, 'b': 2,}, {'a': 1, 'b': 2,}))
print('# test 2: ', __eq__({'a': 1, 'b': {'a': 7},}, {'a': 1, 'b': {'a': 7},}))

obj = {'a': 1,}
obj['b'] = obj
# (built-in __eq__) how does it work - does it match the pointer address?
print('# py-test 3: ', obj == obj)
print('# py-test 3: ', obj['b'] == obj)

# Recursion Error: maximum recursion
# print('# test 3: ', __eq__(obj, obj))
# print('# test 3: ', __eq__(obj['b'], obj))
```
Helper: https://stackoverflow.com/a/63310298/14102601

Live repl example:
![Pointer EQ](https://user-images.githubusercontent.com/38843286/195118507-f085681c-6a8a-4cd4-aa8e-e8057036bf0c.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.