Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

from functools import partial 

 

class _strings(list): 

 

def __init__(self, type_, iterable): 

 

list.__init__(self, [type_(x) for x in (iterable if not isinstance(iterable, str) else 

iterable.split())]) 

self._type = type_ 

 

def __str__(self): 

 

return ' '.join([str(x) for x in self]) 

 

def __add__(self, other): 

 

return _strings(self._type, str(self)+' '+str(_strings(self._type, other))) 

 

def append(self, other): 

 

other = _strings(self._type, other) 

if len(other) > 1: 

raise ValueError('Use extend() to add more than one item') 

super(_strings, self).append(other[0]) 

 

def extend(self, other): 

super(_strings, self).__add__(other) 

 

strings = partial(_strings, str) 

ints = partial(_strings, int) 

floats = partial(_strings, float) 

 

 

class lists(_strings): 

 

def __init__(self, iterable, sep=" + "): 

 

_strings.__init__(self, str, iterable) 

self.n = [strings(x) for x in iterable.split(sep)] 

self.sep = sep 

 

def __add__(self, other): 

 

return lists(str(self)+self.sep+str(other))