4
4
5
5
<summary >Documentation of older versions is available on GitHub.</summary >
6
6
7
+ ▸ [ 0.9.0] ( https://github.com/tfpf/pysorteddict/blob/v0.9.0/docs/documentation.md )
7
8
▸ [ 0.8.2] ( https://github.com/tfpf/pysorteddict/blob/v0.8.2/docs/documentation.md )
8
9
▸ [ 0.8.1] ( https://github.com/tfpf/pysorteddict/blob/v0.8.1/docs/documentation.md )
9
10
▸ [ 0.8.0] ( https://github.com/tfpf/pysorteddict/blob/v0.8.0/docs/documentation.md )
@@ -527,10 +528,29 @@ Uncommenting the commented line runs any required destructors and makes this err
527
528
528
529
Return a shallow copy of the sorted dictionary ` d ` .
529
530
530
- #### ` d.items() -> list[tuple[object, object]] `
531
+ #### ` d.items() -> SortedDictItems `
531
532
532
- Return the key-value pairs in the sorted dictionary ` d ` . The list will be sorted. It will exist independently of ` d ` ;
533
- it won't be a view on its items.
533
+ Return a dynamic view on the items in the sorted dictionary ` d ` .
534
+
535
+ ``` python
536
+ from pysorteddict import *
537
+ d = SortedDict()
538
+ items = d.items()
539
+ d[" foo" ] = ()
540
+ print (items)
541
+ d[" bar" ] = [100 ]
542
+ print (items)
543
+ d[" baz" ] = 3.14
544
+ print (items)
545
+ ```
546
+
547
+ ``` text
548
+ SortedDictItems([('foo', ())])
549
+ SortedDictItems([('bar', [100]), ('foo', ())])
550
+ SortedDictItems([('bar', [100]), ('baz', 3.14), ('foo', ())])
551
+ ```
552
+
553
+ See [ sorted dictionary views] ( #sorted-dictionary-views ) .
534
554
535
555
#### ` d.keys() -> SortedDictKeys `
536
556
@@ -554,21 +574,42 @@ SortedDictKeys(['bar', 'foo'])
554
574
SortedDictKeys(['bar', 'baz', 'foo'])
555
575
```
556
576
557
- See the documentation of [ sorted dictionary views] ( #sorted-dictionary-views ) .
577
+ See [ sorted dictionary views] ( #sorted-dictionary-views ) .
578
+
579
+ #### ` d.values() -> SortedDictValues `
558
580
559
- #### ` d. values() -> list[object] `
581
+ Return a dynamic view on the values in the sorted dictionary ` d ` .
560
582
561
- Return the values in the sorted dictionary ` d ` . The list will be sorted by the keys the values are mapped to. It will
562
- exist independently of ` d ` ; it won't be a view on its values.
583
+ ``` python
584
+ from pysorteddict import *
585
+ d = SortedDict()
586
+ values = d.values()
587
+ d[" foo" ] = ()
588
+ print (values)
589
+ d[" bar" ] = [100 ]
590
+ print (values)
591
+ d[" baz" ] = 3.14
592
+ print (values)
593
+ ```
594
+
595
+ ``` text
596
+ SortedDictValues([()])
597
+ SortedDictValues([[100], ()])
598
+ SortedDictValues([[100], 3.14, ()])
599
+ ```
600
+
601
+ See [ sorted dictionary views] ( #sorted-dictionary-views ) .
563
602
564
603
## Sorted Dictionary Views
565
604
566
605
Sorted dictionary views are dynamic views on a sorted dictionary: they are immutable and cannot be used to mutate the
567
606
sorted dictionary, but always reflect its current state.
568
607
569
- As of the current version, there is only one view type.
608
+ There are three view types:
570
609
571
- * ` SortedDictKeys ` : the return type of ` SortedDict.keys ` .
610
+ * ` SortedDictItems ` , the return type of [ ` SortedDict.items ` ] ( #ditems---sorteddictitems ) ;
611
+ * ` SortedDictKeys ` , the return type of [ ` SortedDict.keys ` ] ( #dkeys---sorteddictkeys ) ; and
612
+ * ` SortedDictValues ` , the return type of [ ` SortedDict.values ` ] ( #dvalues---sorteddictvalues ) .
572
613
573
614
### Magic Methods
574
615
@@ -601,26 +642,28 @@ like when slicing a `list`.
601
642
``` python
602
643
from pysorteddict import *
603
644
d = SortedDict()
604
- keys = d.keys()
645
+ items, keys, values = d.items(), d. keys(), d.values ()
605
646
d[" foo" ] = ()
606
647
d[" bar" ] = [100 ]
607
648
d[" baz" ] = 3.14
608
649
d[" spam" ] = {}
609
650
d[" eggs" ] = " "
610
- print (keys[0 ], keys[2 ], keys[4 ])
651
+ print (d)
652
+ print (keys[0 ], keys[2 ], values[4 ])
611
653
print (keys[:3 ])
612
- print (keys [1 :])
613
- print (keys [- 3 :3 ])
614
- print (keys [- 5 :4 :2 ])
654
+ print (items [1 :])
655
+ print (values [- 3 :3 ])
656
+ print (items [- 5 :4 :2 ])
615
657
print (keys[::- 1 ])
616
658
```
617
659
618
660
``` text
619
- bar eggs spam
661
+ SortedDict({'bar': [100], 'baz': 3.14, 'eggs': '', 'foo': (), 'spam': {}})
662
+ bar eggs {}
620
663
['bar', 'baz', 'eggs']
621
- ['baz', 'eggs', 'foo', 'spam']
622
- ['eggs ']
623
- ['bar', 'eggs']
664
+ [( 'baz', 3.14), ( 'eggs', ''), (' foo', ()), ( 'spam', {}) ]
665
+ ['']
666
+ [( 'bar', [100]), ( 'eggs', '') ]
624
667
['spam', 'foo', 'eggs', 'baz', 'bar']
625
668
```
626
669
0 commit comments