## Query UNT ActiveStudents

0 likes • Nov 18, 2022
Python

## More Python Posts

```import anytree as atimport random as rm
# Generate a tree with node_count many nodes. Each has a number key that shows when it was made and a randomly selected color, red or white.def random_tree(node_count):        # Generates the list of nodes    nodes = []    for i in range(node_count):        test = rm.randint(1,2)        if test == 1:            nodes.append(at.Node(str(i),color="white"))        else:            nodes.append(at.Node(str(i),color="red"))        #Creates the various main branches    for i in range(node_count):        for j in range(i, len(nodes)):            test = rm.randint(1,len(nodes))            if test == 1 and nodes[j].parent == None and (not nodes[i] == nodes[j]):                nodes[j].parent = nodes[i]        #Collects all the main branches into a single tree with the first node being the root    for i in range(1, node_count):        if nodes[i].parent == None and (not nodes[i] == nodes):            nodes[i].parent = nodes
return nodes```
```def max_n(lst, n = 1):  return sorted(lst, reverse = True)[:n]
max_n([1, 2, 3]) # max_n([1, 2, 3], 2) # [3, 2]```
```from collections import Counter
def find_parity_outliers(nums):  return [    x for x in nums    if x % 2 != Counter([n % 2 for n in nums]).most_common()  ]
find_parity_outliers([1, 2, 3, 4, 6]) # [1, 3]```

### hex to rgb

CodeCatch
0 likes • Nov 19, 2022
Python
```def hex_to_rgb(hex):  return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)```
`bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)`
```# Prompt user for a decimal numberdecimal = int(input("Enter a decimal number: "))
# Convert decimal to binarybinary = bin(decimal)