2021-11-17¶
Variables¶
[1]:
a = 42
type(a)
[1]:
int
[2]:
a = 1.7
type(a)
[2]:
float
[3]:
a = [1, 2, 'drei']
type(a)
[3]:
list
[4]:
_a = 666
_123 = 1
[5]:
a = a
[6]:
a = 1
b = 2
c = 3
[7]:
print(a, b, c)
1 2 3
[8]:
a, b, c = 1, 2, 3
[9]:
print(a, b, c)
1 2 3
[10]:
print(a, b, c, sep=',')
1,2,3
Enter Tuples¶
[11]:
a, b, c
[11]:
(1, 2, 3)
[12]:
t = a, b, c
[13]:
t
[13]:
(1, 2, 3)
[14]:
type(t)
[14]:
tuple
[15]:
a, b
[15]:
(1, 2)
Exchange values of a and b, the traditional way
[16]:
c = a
a = b
b = c
a, b
[16]:
(2, 1)
Exchange values, Pythonic
[17]:
a = 1
b = 2
[18]:
a, b = b, a
[19]:
a, b
[19]:
(2, 1)
Name of this: Tuple Unpacking
References¶
[20]:
a = 42
b = a
[21]:
b
[21]:
42
[22]:
id(a)
[22]:
140575811317328
[23]:
id(b)
[23]:
140575811317328
[24]:
b = 7
id(b)
[24]:
140575811316208
Datatypes¶
[25]:
i = 0xffffffff;
[26]:
i
[26]:
4294967295
[27]:
i += 1
[28]:
i
[28]:
4294967296
[29]:
i = 2**64 - 1
[30]:
i
[30]:
18446744073709551615
[31]:
i += 1
[32]:
i
[32]:
18446744073709551616
[33]:
2**100
[33]:
1267650600228229401496703205376
[34]:
2**10000
[34]:
19950631168807583848837421626835850838234968318861924548520089498529438830221946631919961684036194597899331129423209124271556491349413781117593785932096323957855730046793794526765246551266059895520550086918193311542508608460618104685509074866089624888090489894838009253941633257850621568309473902556912388065225096643874441046759871626985453222868538161694315775629640762836880760732228535091641476183956381458969463899410840960536267821064621427333394036525565649530603142680234969400335934316651459297773279665775606172582031407994198179607378245683762280037302885487251900834464581454650557929601414833921615734588139257095379769119277800826957735674444123062018757836325502728323789270710373802866393031428133241401624195671690574061419654342324638801248856147305207431992259611796250130992860241708340807605932320161268492288496255841312844061536738951487114256315111089745514203313820202931640957596464756010405845841566072044962867016515061920631004186422275908670900574606417856951911456055068251250406007519842261898059237118054444788072906395242548339221982707404473162376760846613033778706039803413197133493654622700563169937455508241780972810983291314403571877524768509857276937926433221599399876886660808368837838027643282775172273657572744784112294389733810861607423253291974813120197604178281965697475898164531258434135959862784130128185406283476649088690521047580882615823961985770122407044330583075869039319604603404973156583208672105913300903752823415539745394397715257455290510212310947321610753474825740775273986348298498340756937955646638621874569499279016572103701364433135817214311791398222983845847334440270964182851005072927748364550578634501100852987812389473928699540834346158807043959118985815145779177143619698728131459483783202081474982171858011389071228250905826817436220577475921417653715687725614904582904992461028630081535583308130101987675856234343538955409175623400844887526162643568648833519463720377293240094456246923254350400678027273837755376406726898636241037491410966718557050759098100246789880178271925953381282421954028302759408448955014676668389697996886241636313376393903373455801407636741877711055384225739499110186468219696581651485130494222369947714763069155468217682876200362777257723781365331611196811280792669481887201298643660768551639860534602297871557517947385246369446923087894265948217008051120322365496288169035739121368338393591756418733850510970271613915439590991598154654417336311656936031122249937969999226781732358023111862644575299135758175008199839236284615249881088960232244362173771618086357015468484058622329792853875623486556440536962622018963571028812361567512543338303270029097668650568557157505516727518899194129711337690149916181315171544007728650573189557450920330185304847113818315407324053319038462084036421763703911550639789000742853672196280903477974533320468368795868580237952218629120080742819551317948157624448298518461509704888027274721574688131594750409732115080498190455803416826949787141316063210686391511681774304792596709376
Floor Division
[35]:
3/2
[35]:
1.5
[36]:
3//2
[36]:
1
[37]:
3%2
[37]:
1
[38]:
4%2
[38]:
0
[39]:
if 22%2 == 0:
print('even number')
even number
[40]:
16%3
[40]:
1
[41]:
1+2*3
[41]:
7
[42]:
(1+2)*3
[42]:
9
Strings¶
Datatype Conversions, Type Names¶
[43]:
s = 'abc'
type(s)
[43]:
str
[44]:
s = '666'
type(s)
[44]:
str
[45]:
try:
s += 1
except Exception as e:
print(type(e), e)
<class 'TypeError'> can only concatenate str (not "int") to str
[46]:
i = int(s, 10)
i
[46]:
666
[47]:
type(i)
[47]:
int
[48]:
s = '0x48'
int(s, 16)
[48]:
72
[330]:
s = '1.234'
float(s)
[330]:
1.234
[332]:
s = '1,234' # hm. comma?
try:
float(s)
except Exception as e:
print(type(e), e)
<class 'ValueError'> could not convert string to float: '1,234'
[333]:
s = '1,234' # hm. comma? have to correct this!
s.replace(',', '.')
[333]:
'1.234'
[334]:
float(s.replace(',', '.'))
[334]:
1.234
[49]:
i = 666
s = str(i)
s
[49]:
'666'
[50]:
d = {'eins': 1, 'zwei': 2}
dstr = str(d)
dstr
[50]:
"{'eins': 1, 'zwei': 2}"
[51]:
i = 666
print(type(i))
<class 'int'>
[52]:
f = float(i)
f
[52]:
666.0
[53]:
f = 666.777
i = int(f)
i
[53]:
666
[54]:
round(f)
[54]:
667
[55]:
s = 'abc'
l = list(s)
l
[55]:
['a', 'b', 'c']
[56]:
try:
list(666)
except Exception as e:
print(type(e), e)
<class 'TypeError'> 'int' object is not iterable
Type names are variables (or so)
[57]:
type(666)
[57]:
int
[58]:
a = 666
type(a)
[58]:
int
[59]:
type(int)
[59]:
type
[60]:
type(bool)
[60]:
type
[61]:
type(dict)
[61]:
type
[62]:
int('666')
[62]:
666
[63]:
type(int)
[63]:
type
At this point, the name “int” refer to the integer type (“int” is a variable that refers to a type object). Now, we assign an int object to the “int” variable.
[64]:
int = 666
[65]:
int
[65]:
666
The type int is apparently gone!
[66]:
type(int)
[66]:
int
[67]:
try:
i = int('666')
except Exception as e:
print(type(e), e)
<class 'TypeError'> 'int' object is not callable
WTF?? How to repair this??!!
[68]:
type(666) # int is still alive!!
[68]:
int
[69]:
int = type(666)
[70]:
type(int)
[70]:
type
[71]:
int('666')
[71]:
666
Compound Datatypes¶
List¶
[72]:
l = [1, 2, 3]
l
[72]:
[1, 2, 3]
[73]:
len(l)
[73]:
3
Question: is something in the list?
[74]:
2 in l
[74]:
True
[75]:
not 2 in l
[75]:
False
[76]:
2 not in l
[76]:
False
[77]:
100 in l
[77]:
False
[78]:
l.append(4)
[79]:
l
[79]:
[1, 2, 3, 4]
[80]:
l.extend([5, 6, 7])
[81]:
l
[81]:
[1, 2, 3, 4, 5, 6, 7]
Attention
[82]:
l.append([8, 9, 10]) # appends only one element of type list!
l
[82]:
[1, 2, 3, 4, 5, 6, 7, [8, 9, 10]]
[83]:
l.extend('abc') # appends three elements of type str (one character each)
l
[83]:
[1, 2, 3, 4, 5, 6, 7, [8, 9, 10], 'a', 'b', 'c']
[84]:
l.extend(range(4))
l
[84]:
[1, 2, 3, 4, 5, 6, 7, [8, 9, 10], 'a', 'b', 'c', 0, 1, 2, 3]
[ ]:
Tuple¶
[85]:
t = (1, 2, 3)
[86]:
t
[86]:
(1, 2, 3)
[87]:
len(t)
[87]:
3
[88]:
try:
t.append(4)
except Exception as e:
print(e)
'tuple' object has no attribute 'append'
Dictionary¶
[89]:
map = {
'eins': 1,
'zwei': 2,
}
type(map)
[89]:
dict
[90]:
len(map)
[90]:
2
[91]:
'zwei' in map
[91]:
True
[92]:
'drei' in map
[92]:
False
[93]:
map['eins']
[93]:
1
[94]:
map['drei'] = 3
[95]:
map
[95]:
{'eins': 1, 'zwei': 2, 'drei': 3}
[96]:
map['zwei'] = 2.0
[97]:
map
[97]:
{'eins': 1, 'zwei': 2.0, 'drei': 3}
[98]:
try:
map['vier']
except KeyError as e:
print(type(e), e)
<class 'KeyError'> 'vier'
Set¶
[99]:
s = {1, 2, 3}
[100]:
len(s)
[100]:
3
[101]:
2 in s
[101]:
True
[102]:
s.add(100)
[103]:
s
[103]:
{1, 2, 3, 100}
[104]:
s.add('/path/to/something')
[105]:
s
[105]:
{'/path/to/something', 1, 100, 2, 3}
[106]:
{1, 2, 3} - {2, 3, 4} # difference
[106]:
{1}
Question: can I use a string as a set?
[107]:
try:
"abc" - "bcd"
except Exception as e:
print(type(e), e)
<class 'TypeError'> unsupported operand type(s) for -: 'str' and 'str'
[108]:
s = set("abc")
s
[108]:
{'a', 'b', 'c'}
[109]:
s = set(range(10))
s
[109]:
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
[110]:
s = set([3, 1000, 'vier'])
s
[110]:
{1000, 3, 'vier'}
[111]:
3 in s
[111]:
True
Boolean¶
[112]:
1 < 2
[112]:
True
[113]:
type(1<2)
[113]:
bool
[114]:
b = True
[115]:
if 1:
print('hm')
hm
[116]:
if 100:
print('hm')
hm
[117]:
if 0:
print('hm')
[118]:
bool(0)
[118]:
False
[119]:
bool(100)
[119]:
True
Attention: boolean values of compound types
[120]:
s = {}
bool(s)
[120]:
False
[121]:
bool('')
[121]:
False
[122]:
bool('abc')
[122]:
True
NoneType¶
[123]:
a = None
type(a)
[123]:
NoneType
[124]:
def f(s):
if s:
print('jo')
else:
print('na')
[125]:
f({1, 2, 3})
jo
[126]:
f({})
na
[127]:
f(None)
na
[128]:
def f(s):
if s is None:
print('na')
else:
print('ja')
[129]:
f(None)
na
[130]:
f({})
ja
Short Circuit Evaluation of Boolean Expression¶
[131]:
True or False
[131]:
True
[132]:
if 1 in {1, 2} or type('abc') is int:
print('jo')
jo
[133]:
False or True
[133]:
True
[134]:
True and False
[134]:
False
[135]:
False and True
[135]:
False
[136]:
if 1 in {1, 2} and type('abc') is int:
print('jo')
else:
print('na')
na
[137]:
False or False
[137]:
False
[138]:
True and True
[138]:
True
[139]:
bool(print('hallo')) # print has a boolean value
hallo
[139]:
False
[140]:
1 == 2 and print('hallo') # note: we do not see 'hallo'
[140]:
False
[141]:
1 == 2 or print('hallo')
hallo
[142]:
not True
[142]:
False
Exercise: Mixed List¶
[143]:
d = {'eins': 1, 'zwei': 2} # dict
[144]:
xxx = 1, 2
[145]:
xxx
[145]:
(1, 2)
[146]:
type(xxx)
[146]:
tuple
[147]:
d = {'eins':1}, {'zwei': 2} # tuple :-) :-) :-)
[148]:
type(d)
[148]:
tuple
Day 2¶
Python Documentation¶
String examples
[149]:
s = 'mississippi'
[150]:
s.count('ss')
[150]:
2
[151]:
s.capitalize()
[151]:
'Mississippi'
[152]:
s
[152]:
'mississippi'
[153]:
s = '1,2,3,4'
[154]:
items = s.split(',')
[155]:
items
[155]:
['1', '2', '3', '4']
[156]:
'-'.join(items)
[156]:
'1-2-3-4'
[157]:
s.replace(',', '-')
[157]:
'1-2-3-4'
[158]:
a = 'dusan'
b = 'alex'
'+'.join([a, b])
[158]:
'dusan+alex'
[159]:
s = ' das sind die nutzdaten, alles andere ist mist '
[160]:
s.strip()
[160]:
'das sind die nutzdaten, alles andere ist mist'
[161]:
s.strip().split(' ')
[161]:
['das', 'sind', 'die', 'nutzdaten,', 'alles', 'andere', 'ist', 'mist']
Regular Expressions
[162]:
s = '2021-11-17' # hm: year, month, day
[163]:
import re
match = re.search('^(\d{4})-(\d+)-(\d+)$', s)
match
[163]:
<re.Match object; span=(0, 10), match='2021-11-17'>
[164]:
match.group(1)
[164]:
'2021'
[165]:
match.group(2)
[165]:
'11'
[166]:
match.group(3)
[166]:
'17'
Where is ``pi``
[167]:
import math
math.pi
[167]:
3.141592653589793
Random numbers
[168]:
import random
[169]:
random.randrange(10, 100)
[169]:
61
Paths, Filenames, Directories
[170]:
import os.path
[171]:
dirname = '/home/jfasch'
filename = '.bashrc'
[172]:
os.path.join(dirname, filename)
[172]:
'/home/jfasch/.bashrc'
while
¶
[173]:
# sum of number 1..10
i = 1
s = 0 # the future sum
while i <= 10:
print(i)
s += i
i += 1
print('the sum is:', s)
1
2
3
4
5
6
7
8
9
10
the sum is: 55
[174]:
# roll dice (at most 10 times) until we see 6
import random
win = False
n = 0
while n < 10:
rnd = random.randrange(1, 7)
if rnd == 6:
win = True
break
n += 1
if win:
print('yay!')
else:
print('you lost!')
yay!
[175]:
# roll dice (at most 10 times) until we see 6
import random
n = 0
while n < 10:
rnd = random.randrange(1, 7)
if rnd == 6:
print('yay!')
break
n += 1
else:
print('you lost!')
yay!
for
¶
[176]:
# roll dice (at most 10 times) until we see 6
import random
for _ in range(10): # use '_' to conventionally state that we do not use this variable
rnd = random.randrange(1, 7)
if rnd == 6:
print('yay!')
break
else:
print('you lost!')
yay!
Iteration over Compound Datatypes¶
List
[177]:
l = [1, 2, 'drei']
for element in l:
print(element)
1
2
drei
Tuple
[178]:
t = (1, 2, 'drei')
for element in t:
print(element)
1
2
drei
Set
[179]:
s = set()
for i in range(20):
s.add(i)
s.add('drei')
s
[179]:
{0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 3, 4, 5, 6, 7, 8, 9, 'drei'}
[180]:
for element in s:
print(element)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
drei
Dictionary
[181]:
map = {
'eins': 1,
'zwei': 2,
'drei': 3,
}
[182]:
for element in map: # implicitly iterates over keys
print(element)
eins
zwei
drei
[183]:
for key in map.keys(): # explicitly iterates over keys (better)
print(key)
eins
zwei
drei
[184]:
for value in map.values():
print(value)
1
2
3
[185]:
for element in map.items(): # pairwise iteration -> tuples
print(element, type(element))
('eins', 1) <class 'tuple'>
('zwei', 2) <class 'tuple'>
('drei', 3) <class 'tuple'>
Tuple unpacking
[186]:
a, b = 1, 2
a, b
[186]:
(1, 2)
[187]:
a, b = b, a
[188]:
for element in map.items():
key = element[0]
value = element[1]
print('key:', key, ', value:', value)
key: eins , value: 1
key: zwei , value: 2
key: drei , value: 3
[189]:
for key, value in map.items():
print('key:', key, ', value:', value)
key: eins , value: 1
key: zwei , value: 2
key: drei , value: 3
Tuple unpacking, Database-wise
[190]:
resultset = [ # SVNr, Firstname, Lastname
(1, 'Joerg', 'Faschingbauer'),
(3, 'Johanna', 'Faschingbauer'),
(2, 'Caro', 'Faschingbauer'),
]
for svnr, first, last in resultset:
print(f'SVNr: {svnr}, Firstname: {first}, Lastname: {last}')
SVNr: 1, Firstname: Joerg, Lastname: Faschingbauer
SVNr: 3, Firstname: Johanna, Lastname: Faschingbauer
SVNr: 2, Firstname: Caro, Lastname: Faschingbauer
File IO¶
[191]:
f = open('passwd')
[192]:
f
[192]:
<_io.TextIOWrapper name='passwd' mode='r' encoding='UTF-8'>
[193]:
line = f.readline()
line
[193]:
'root:x:0:0:root:/root:/bin/bash\n'
[194]:
line = f.readline()
line
[194]:
'bin:x:1:1:bin:/bin:/sbin/nologin\n'
[195]:
f = open('passwd')
[196]:
for line in f:
print(line)
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
systemd-oom:x:998:996:systemd Userspace OOM Killer:/:/sbin/nologin
systemd-timesync:x:997:995:systemd Time Synchronization:/:/sbin/nologin
tss:x:59:59:Account used for TPM access:/dev/null:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:996:994:User for polkitd:/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
unbound:x:995:992:Unbound DNS resolver:/etc/unbound:/sbin/nologin
dnsmasq:x:994:991:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/sbin/nologin
nm-openconnect:x:993:989:NetworkManager user for OpenConnect:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
gluster:x:992:988:GlusterFS daemons:/run/gluster:/sbin/nologin
rtkit:x:172:172:RealtimeKit:/proc:/sbin/nologin
pipewire:x:991:987:PipeWire System Daemon:/var/run/pipewire:/sbin/nologin
geoclue:x:990:986:User for geoclue:/var/lib/geoclue:/sbin/nologin
chrony:x:989:984::/var/lib/chrony:/sbin/nologin
saslauth:x:988:76:Saslauthd user:/run/saslauthd:/sbin/nologin
radvd:x:75:75:radvd user:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
qemu:x:107:107:qemu user:/:/sbin/nologin
openvpn:x:987:982:OpenVPN:/etc/openvpn:/sbin/nologin
nm-openvpn:x:986:981:Default user for running openvpn spawned by NetworkManager:/:/sbin/nologin
colord:x:985:980:User for colord:/var/lib/colord:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
flatpak:x:984:979:User for flatpak system helper:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
gnome-initial-setup:x:983:978::/run/gnome-initial-setup/:/sbin/nologin
vboxadd:x:982:1::/var/run/vboxadd:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
jfasch:x:1000:1000:Joerg Faschingbauer:/home/jfasch:/bin/bash
mosquitto:x:981:974:Mosquitto Broker:/etc/mosquitto:/sbin/nologin
Day 3¶
[197]:
def maximum(a, b):
if a < b:
return b
else:
return a
[198]:
maximum(1, 2)
[198]:
2
[199]:
maximum('a', 'b')
[199]:
'b'
[200]:
maximum([1, 2, 3], [4, 5, 6])
[200]:
[4, 5, 6]
[201]:
try:
maximum(1, 'abc')
except Exception as e:
print(type(e), e)
<class 'TypeError'> '<' not supported between instances of 'int' and 'str'
[202]:
class A:
def __init__(self, a, b):
self.a = a
self.b = b
def doit(self):
print(self.a, self.b)
[203]:
a = A(2, 3)
a.doit()
2 3
[204]:
type(A)
[204]:
type
[205]:
A.__dict__
[205]:
mappingproxy({'__module__': '__main__',
'__init__': <function __main__.A.__init__(self, a, b)>,
'doit': <function __main__.A.doit(self)>,
'__dict__': <attribute '__dict__' of 'A' objects>,
'__weakref__': <attribute '__weakref__' of 'A' objects>,
'__doc__': None})
[206]:
# s = 'def xxx(self): print("xxx jessas")'
# exec(s, A.__dict__)
The range()
Function¶
[207]:
for i in [0,1,2,3,4,5,6,7,8,9]:
print(i)
0
1
2
3
4
5
6
7
8
9
[208]:
for i in range(10):
print(i)
0
1
2
3
4
5
6
7
8
9
[209]:
for i in range(10, 2): # begin 10, end 2 -> nothing in between
print(i)
[210]:
for i in range(0, 10, 2):
print(i)
0
2
4
6
8
[211]:
# 10+1 = 11
for i in range(0, 10+1, 2):
print(i)
0
2
4
6
8
10
Generators, Iterator Protocol, for
¶
[212]:
range(3)
[212]:
range(0, 3)
[213]:
r = range(3)
r
[213]:
range(0, 3)
[214]:
type(r)
[214]:
range
[215]:
for i in r:
print(i)
0
1
2
[216]:
r = range(3)
[217]:
it = iter(r)
[218]:
type(it)
[218]:
range_iterator
[219]:
i = next(it)
i
[219]:
0
[220]:
i = next(it)
i
[220]:
1
[221]:
i = next(it)
i
[221]:
2
[222]:
try:
i = next(it)
except Exception as e:
print(type(e), e)
<class 'StopIteration'>
Common Sequence Operation¶
[223]:
s = 'abc'
[224]:
s + s
[224]:
'abcabc'
[225]:
s*2
[225]:
'abcabc'
[226]:
[1, 2, 3]*2
[226]:
[1, 2, 3, 1, 2, 3]
[227]:
l = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Slicing
[228]:
l[2:4]
[228]:
['c', 'd']
[229]:
'abcde'[2:4]
[229]:
'cd'
[230]:
l[1:6:2]
[230]:
['b', 'd', 'f']
[231]:
l[2:4] = [1, 2, 3, 4]
[232]:
l
[232]:
['a', 'b', 1, 2, 3, 4, 'e', 'f', 'g', 'h']
Comprehensions¶
[233]:
l = [1, 2, 3, 4, 5]
[234]:
def squares(inputlist):
ret = []
for i in inputlist:
ret.append(i**2)
return ret
[235]:
sq = squares(l)
sq
[235]:
[1, 4, 9, 16, 25]
[236]:
squares(range(1, 6))
[236]:
[1, 4, 9, 16, 25]
List Comprehension
[237]:
sq = [i**2 for i in l]
type(sq)
[237]:
list
[238]:
sq
[238]:
[1, 4, 9, 16, 25]
[239]:
[i**2 for i in range(10)]
[239]:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[240]:
[i**2 for i in range(10) if i%2 == 0]
[240]:
[0, 4, 16, 36, 64]
[241]:
[i**2 for i in range(0, 10, 2)]
[241]:
[0, 4, 16, 36, 64]
Set Comprehensions
[242]:
wtf = {i**2 for i in range(10) if i%2 == 0}
type(wtf)
[242]:
set
[243]:
wtf
[243]:
{0, 4, 16, 36, 64}
Dictionary Comprehension
[244]:
wtf = {i: i**2 for i in range(10)}
type(wtf)
[244]:
dict
[245]:
print(wtf)
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
List, Iterable? WTF?¶
[246]:
l = list(range(10))
[247]:
l
[247]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[248]:
l = list('abc')
l
[248]:
['a', 'b', 'c']
Dict and iterable¶
[249]:
l = [('eins', 1), ('zwei', 2), ('drei', 3)]
for k, v in l:
print(k, v)
eins 1
zwei 2
drei 3
[250]:
map = dict(l)
map
[250]:
{'eins': 1, 'zwei': 2, 'drei': 3}
More on Lists¶
[251]:
l = [3, 2, 1, 4, 7, 5]
[252]:
del l[2]
[253]:
l
[253]:
[3, 2, 4, 7, 5]
[254]:
sorted(l) # returns a sorted list
[254]:
[2, 3, 4, 5, 7]
[255]:
l
[255]:
[3, 2, 4, 7, 5]
[256]:
l.sort() # sort l in place
[257]:
l
[257]:
[2, 3, 4, 5, 7]
[258]:
reversed(l)
[258]:
<list_reverseiterator at 0x7fda5444e6a0>
[259]:
l.reverse()
[260]:
l
[260]:
[7, 5, 4, 3, 2]
More on Dictionaries¶
[261]:
map = {'eins': 1, 'zwei': 2}
[262]:
map['eins']
[262]:
1
[263]:
try:
map['drei']
except Exception as e:
print(type(e), e)
<class 'KeyError'> 'drei'
[264]:
if map.get('drei') is None: #
print('not found')
else:
print('found')
not found
[265]:
if map.get('zwei') is None: #
print('not found')
else:
print('found')
found
[266]:
v = map.get('zwei')
v
[266]:
2
[267]:
v = map.get('drei', 3)
v
[267]:
3
[268]:
map
[268]:
{'eins': 1, 'zwei': 2}
[269]:
del map['zwei']
[270]:
map
[270]:
{'eins': 1}
[271]:
other_map = {'eins': 1, 'zwei': 2, 'vier': 4}
[272]:
map.update(other_map)
map
[272]:
{'eins': 1, 'zwei': 2, 'vier': 4}
References, Mutability¶
Integers are Immutable
[273]:
a = 10
b = a
[274]:
id(a)
[274]:
140575811316304
[275]:
id(b)
[275]:
140575811316304
[276]:
b = 42
a
[276]:
10
[277]:
a = 10
b = a
[278]:
a = 42
b
[278]:
10
Lists are Mutable
[279]:
l1 = [1, 2, 3]
l2 = l1
[280]:
id(l1)
[280]:
140575692459008
[281]:
id(l2)
[281]:
140575692459008
[282]:
l2.append(4)
l2
[282]:
[1, 2, 3, 4]
[283]:
l1
[283]:
[1, 2, 3, 4]
Protect against such errors?
[284]:
l1 = [1, 2, 3]
l2 = l1[:] # slice [begin:end] -> elementwise copy
[285]:
l1
[285]:
[1, 2, 3]
[286]:
l2
[286]:
[1, 2, 3]
[287]:
id(l1)
[287]:
140575692438848
[288]:
id(l2)
[288]:
140575692448960
[289]:
l2.append(4)
[290]:
l2
[290]:
[1, 2, 3, 4]
[292]:
l1
[292]:
[1, 2, 3]
Hm …
[293]:
l1 = [1, 2, ['drei', 'vier'], 5, 6]
len(l1)
[293]:
5
[295]:
l2 = l1[:]
l2
[295]:
[1, 2, ['drei', 'vier'], 5, 6]
[296]:
l2[2].append('fuenf')
l2
[296]:
[1, 2, ['drei', 'vier', 'fuenf'], 5, 6]
[298]:
l1
[298]:
[1, 2, ['drei', 'vier', 'fuenf'], 5, 6]
—> Shallow copy
Deep copy?
[300]:
l1 = [1, 2, ['drei', 'vier'], 5, 6]
[301]:
import copy
[302]:
l2 = copy.deepcopy(l1)
l2
[302]:
[1, 2, ['drei', 'vier'], 5, 6]
[303]:
l2[2].append('fuenf')
l2
[303]:
[1, 2, ['drei', 'vier', 'fuenf'], 5, 6]
[304]:
l1
[304]:
[1, 2, ['drei', 'vier'], 5, 6]
CSV¶
[305]:
import csv
[314]:
f = open('code/beispiel.csv')
[315]:
rdr = csv.reader(f, delimiter=';')
for row in rdr:
print(row)
['FUND_NAME', 'FUND_ISIN', 'FUND_TICKER', 'AS_OF_DATE', 'FUND_IN_UNIVERSE', 'FUND_OF_FUNDS', 'FUND_HOLDINGS_COUNT', 'FUND_HOLDING_FUNDS_COUNT']
['American Funds American Balanced Fund;A', 'US0240711020', 'ABALX', '20210103', 'T', '', '2,084', '0']
['Dodge & Cox Balanced Fund', 'US2562011047', 'DODBX', '20210103', 'T', 'T', '410', '1']
['Dodge & Cox Stock Fund', 'US2562191062', 'DODGX', '20210103', 'T', 'T', '74', '1']
['Franklin Income Fund;A1', 'US3534963000', 'FKINX', '20210103', 'T', 'T', '302', '1']
['American Funds Growth Fund of America;A', 'US3998741066', 'AGTHX', '20210103', 'T', '', '378', '0']
['T Rowe Price Growth Stock Fund', 'US7414791092', 'PRGFX', '20210103', 'T', 'T', '87', '1']
['Fidelity Puritan Fund', 'US3163451079', 'FPURX', '20210103', 'T', '', '1,124', '0']
['Fidelity Contrafund', 'US3160711095', 'FCNTX', '20210103', 'T', '', '363', '0']
['T Rowe Price Capital Appreciation Fund', 'US77954M1053', 'PRWCX', '20210103', 'T', 'T', '165', '2']
['Old Westbury Large Cap Strategies Fund', 'US6804141090', 'OWLSX', '20210103', 'T', 'T', '199', '2']
['American Funds Capital Income Builder;A', 'US1401931035', 'CAIBX', '20210103', 'T', '', '1,582', '0']
['Harbor Capital Appreciation Fund;Institutional', 'US4115115044', 'HACAX', '20210103', 'T', '', '55', '0']
['T Rowe Price Blue Chip Growth Fund', 'US77954Q1067', 'TRBCX', '20210103', 'T', 'T', '123', '1']
['Dreyfus Treasury Securities Cash Management;Inst', 'US2619411083', 'DIRXX', '20210103', 'T', '', '50', '0']
['BlackRock Global Allocation Fund;Institutional', 'US09251T5092', 'MALOX', '20210103', 'T', 'T', '1,241', '16']
['Fidelity Low-Priced Stock Fund', 'US3163453059', 'FLPSX', '20210103', 'T', '', '799', '0']
['BlackRock Liquidity Treasury Trust Fund;Inst', 'US09248U5517', 'TTTXX', '20210103', 'T', '', '63', '0']
['DFA Five-Year Global Fixed Income Portfolio;Inst', 'US2332038841', 'DFGBX', '20210103', 'T', '', '350', '0']
['Federated Hermes US Treasury Cash Reserves;Inst', 'US60934N6821', 'UTIXX', '20210103', 'T', '', '55', '0']
['Oakmark International Fund;Investor', 'US4138382027', 'OAKIX', '20210103', 'T', '', '80', '0']
['Advanced Srs T Rowe Price Asset Allocation Port', 'US00767H4939', '', '20210103', 'T', '', '2,787', '0']
['FPA Crescent Fund;Inst', 'US30254T7596', 'FPACX', '20210103', 'T', '', '138', '0']
['Franklin Income Fund;C', 'US3534968058', 'FCISX', '20210103', 'T', 'T', '302', '1']
['MFS Value Fund;I', 'US5529836943', 'MEIIX', '20210103', 'T', '', '76', '0']
['Goldman Sachs FS Treasury Instruments Fd;Inst', 'US38142B5003', 'FTIXX', '20210103', 'T', '', '67', '0']
['Schwab S&P 500 Index Fund', 'US8085098551', 'SWPPX', '20210103', 'T', '', '508', '0']
['Templeton Global Bond Fund;Advisor', 'US8802084009', 'TGBAX', '20210103', 'T', 'T', '82', '1']
['First Eagle Global Fund;I', 'US32008F6060', 'SGIIX', '20210103', 'T', 'T', '225', '1']
['iShares Core S&P 500 ETF', 'US4642872000', 'IVV', '20210103', 'T', 'T', '507', '1']
['Vanguard 500 Index Fund;Admiral', 'US9229087104', 'VFIAX', '20210103', 'T', '', '510', '0']
['Vanguard Total Stock Market Index Fund;Admiral', 'US9229087286', 'VTSAX', '20210103', 'T', '', '3,370', '0']
['SPDR S&P MidCap 400 ETF', 'US78467Y1073', 'MDY', '20210103', 'T', '', '400', '0']
['SPDR Dow Jones Industrial Average ETF Trust', 'US78467X1090', 'DIA', '20210103', 'T', '', '31', '0']
['Health Care Select Sector SPDR Fund', 'US81369Y2090', 'XLV', '20210103', 'T', 'T', '64', '1']
['Consumer Discretionary Select Sector SPDR Fund', 'US81369Y4070', 'XLY', '20210103', 'T', 'T', '62', '1']
['Energy Select Sector SPDR Fund', 'US81369Y5069', 'XLE', '20210103', 'T', 'T', '28', '1']
['Financial Select Sector SPDR Fund', 'US81369Y6059', 'XLF', '20210103', 'T', 'T', '66', '1']
['Technology Select Sector SPDR Fund', 'US81369Y8030', 'XLK', '20210103', 'T', 'T', '74', '1']
['Invesco QQQ Trust Series 1', 'US46090E1038', 'QQQ', '20210103', 'T', '', '104', '0']
['Dodge & Cox International Stock Fund', 'US2562061034', 'DODFX', '20210103', 'T', 'T', '80', '1']
['iShares MSCI EAFE ETF', 'US4642874659', 'EFA', '20210103', 'T', 'T', '897', '1']
['JPMorgan 100% US Treasury Secs Mny Mkt Fd;Inst', 'US4812A28358', 'JTSXX', '20210103', 'T', '', '41', '0']
['Invesco S&P 500 Eql Wght ETF', 'US46137V3574', 'RSP', '20210103', 'T', 'T', '507', '1']
['JPMorgan 100% US Treasury Secs Mny Mkt Fd;Capital', 'US4812A03757', 'CJTXX', '20210103', 'T', '', '41', '0']
['Invesco Developing Markets Fund;Y', 'US00143W8753', 'ODVYX', '20210103', 'T', 'T', '72', '3']
['SPDR S&P Dividend ETF', 'US78464A7634', 'SDY', '20210103', 'T', 'T', '118', '1']
['DFA International Core Equity Portfolio;Inst', 'US2332033719', 'DFIEX', '20210103', 'T', '', '4,888', '0']
['Edgewood Growth Fund;Institutional', 'US0075W07594', 'EGFIX', '20210103', 'T', 'T', '23', '1']
['Advanced Series Prudential Growth Allocation Port', 'US00767H7585', '', '20210103', 'T', 'T', '2,400', '3']
['MFS Value Fund;R6', 'US55273H3536', 'MEIKX', '20210103', 'T', '', '76', '0']
[327]:
f = open('code/beispiel.csv')
[328]:
rdr = csv.DictReader(f, delimiter=';')
for elem in rdr:
print(elem)
{'FUND_NAME': 'American Funds American Balanced Fund;A', 'FUND_ISIN': 'US0240711020', 'FUND_TICKER': 'ABALX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '2,084', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Dodge & Cox Balanced Fund', 'FUND_ISIN': 'US2562011047', 'FUND_TICKER': 'DODBX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '410', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Dodge & Cox Stock Fund', 'FUND_ISIN': 'US2562191062', 'FUND_TICKER': 'DODGX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '74', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Franklin Income Fund;A1', 'FUND_ISIN': 'US3534963000', 'FUND_TICKER': 'FKINX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '302', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'American Funds Growth Fund of America;A', 'FUND_ISIN': 'US3998741066', 'FUND_TICKER': 'AGTHX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '378', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'T Rowe Price Growth Stock Fund', 'FUND_ISIN': 'US7414791092', 'FUND_TICKER': 'PRGFX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '87', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Fidelity Puritan Fund', 'FUND_ISIN': 'US3163451079', 'FUND_TICKER': 'FPURX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '1,124', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Fidelity Contrafund', 'FUND_ISIN': 'US3160711095', 'FUND_TICKER': 'FCNTX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '363', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'T Rowe Price Capital Appreciation Fund', 'FUND_ISIN': 'US77954M1053', 'FUND_TICKER': 'PRWCX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '165', 'FUND_HOLDING_FUNDS_COUNT': '2'}
{'FUND_NAME': 'Old Westbury Large Cap Strategies Fund', 'FUND_ISIN': 'US6804141090', 'FUND_TICKER': 'OWLSX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '199', 'FUND_HOLDING_FUNDS_COUNT': '2'}
{'FUND_NAME': 'American Funds Capital Income Builder;A', 'FUND_ISIN': 'US1401931035', 'FUND_TICKER': 'CAIBX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '1,582', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Harbor Capital Appreciation Fund;Institutional', 'FUND_ISIN': 'US4115115044', 'FUND_TICKER': 'HACAX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '55', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'T Rowe Price Blue Chip Growth Fund', 'FUND_ISIN': 'US77954Q1067', 'FUND_TICKER': 'TRBCX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '123', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Dreyfus Treasury Securities Cash Management;Inst', 'FUND_ISIN': 'US2619411083', 'FUND_TICKER': 'DIRXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '50', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'BlackRock Global Allocation Fund;Institutional', 'FUND_ISIN': 'US09251T5092', 'FUND_TICKER': 'MALOX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '1,241', 'FUND_HOLDING_FUNDS_COUNT': '16'}
{'FUND_NAME': 'Fidelity Low-Priced Stock Fund', 'FUND_ISIN': 'US3163453059', 'FUND_TICKER': 'FLPSX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '799', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'BlackRock Liquidity Treasury Trust Fund;Inst', 'FUND_ISIN': 'US09248U5517', 'FUND_TICKER': 'TTTXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '63', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'DFA Five-Year Global Fixed Income Portfolio;Inst', 'FUND_ISIN': 'US2332038841', 'FUND_TICKER': 'DFGBX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '350', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Federated Hermes US Treasury Cash Reserves;Inst', 'FUND_ISIN': 'US60934N6821', 'FUND_TICKER': 'UTIXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '55', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Oakmark International Fund;Investor', 'FUND_ISIN': 'US4138382027', 'FUND_TICKER': 'OAKIX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '80', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Advanced Srs T Rowe Price Asset Allocation Port', 'FUND_ISIN': 'US00767H4939', 'FUND_TICKER': '', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '2,787', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'FPA Crescent Fund;Inst', 'FUND_ISIN': 'US30254T7596', 'FUND_TICKER': 'FPACX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '138', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Franklin Income Fund;C', 'FUND_ISIN': 'US3534968058', 'FUND_TICKER': 'FCISX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '302', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'MFS Value Fund;I', 'FUND_ISIN': 'US5529836943', 'FUND_TICKER': 'MEIIX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '76', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Goldman Sachs FS Treasury Instruments Fd;Inst', 'FUND_ISIN': 'US38142B5003', 'FUND_TICKER': 'FTIXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '67', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Schwab S&P 500 Index Fund', 'FUND_ISIN': 'US8085098551', 'FUND_TICKER': 'SWPPX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '508', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Templeton Global Bond Fund;Advisor', 'FUND_ISIN': 'US8802084009', 'FUND_TICKER': 'TGBAX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '82', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'First Eagle Global Fund;I', 'FUND_ISIN': 'US32008F6060', 'FUND_TICKER': 'SGIIX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '225', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'iShares Core S&P 500 ETF', 'FUND_ISIN': 'US4642872000', 'FUND_TICKER': 'IVV', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '507', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Vanguard 500 Index Fund;Admiral', 'FUND_ISIN': 'US9229087104', 'FUND_TICKER': 'VFIAX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '510', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Vanguard Total Stock Market Index Fund;Admiral', 'FUND_ISIN': 'US9229087286', 'FUND_TICKER': 'VTSAX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '3,370', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'SPDR S&P MidCap 400 ETF', 'FUND_ISIN': 'US78467Y1073', 'FUND_TICKER': 'MDY', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '400', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'SPDR Dow Jones Industrial Average ETF Trust', 'FUND_ISIN': 'US78467X1090', 'FUND_TICKER': 'DIA', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '31', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Health Care Select Sector SPDR Fund', 'FUND_ISIN': 'US81369Y2090', 'FUND_TICKER': 'XLV', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '64', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Consumer Discretionary Select Sector SPDR Fund', 'FUND_ISIN': 'US81369Y4070', 'FUND_TICKER': 'XLY', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '62', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Energy Select Sector SPDR Fund', 'FUND_ISIN': 'US81369Y5069', 'FUND_TICKER': 'XLE', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '28', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Financial Select Sector SPDR Fund', 'FUND_ISIN': 'US81369Y6059', 'FUND_TICKER': 'XLF', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '66', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Technology Select Sector SPDR Fund', 'FUND_ISIN': 'US81369Y8030', 'FUND_TICKER': 'XLK', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '74', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Invesco QQQ Trust Series 1', 'FUND_ISIN': 'US46090E1038', 'FUND_TICKER': 'QQQ', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '104', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Dodge & Cox International Stock Fund', 'FUND_ISIN': 'US2562061034', 'FUND_TICKER': 'DODFX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '80', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'iShares MSCI EAFE ETF', 'FUND_ISIN': 'US4642874659', 'FUND_TICKER': 'EFA', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '897', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'JPMorgan 100% US Treasury Secs Mny Mkt Fd;Inst', 'FUND_ISIN': 'US4812A28358', 'FUND_TICKER': 'JTSXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '41', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Invesco S&P 500 Eql Wght ETF', 'FUND_ISIN': 'US46137V3574', 'FUND_TICKER': 'RSP', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '507', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'JPMorgan 100% US Treasury Secs Mny Mkt Fd;Capital', 'FUND_ISIN': 'US4812A03757', 'FUND_TICKER': 'CJTXX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '41', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Invesco Developing Markets Fund;Y', 'FUND_ISIN': 'US00143W8753', 'FUND_TICKER': 'ODVYX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '72', 'FUND_HOLDING_FUNDS_COUNT': '3'}
{'FUND_NAME': 'SPDR S&P Dividend ETF', 'FUND_ISIN': 'US78464A7634', 'FUND_TICKER': 'SDY', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '118', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'DFA International Core Equity Portfolio;Inst', 'FUND_ISIN': 'US2332033719', 'FUND_TICKER': 'DFIEX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '4,888', 'FUND_HOLDING_FUNDS_COUNT': '0'}
{'FUND_NAME': 'Edgewood Growth Fund;Institutional', 'FUND_ISIN': 'US0075W07594', 'FUND_TICKER': 'EGFIX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '23', 'FUND_HOLDING_FUNDS_COUNT': '1'}
{'FUND_NAME': 'Advanced Series Prudential Growth Allocation Port', 'FUND_ISIN': 'US00767H7585', 'FUND_TICKER': '', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': 'T', 'FUND_HOLDINGS_COUNT': '2,400', 'FUND_HOLDING_FUNDS_COUNT': '3'}
{'FUND_NAME': 'MFS Value Fund;R6', 'FUND_ISIN': 'US55273H3536', 'FUND_TICKER': 'MEIKX', 'AS_OF_DATE': '20210103', 'FUND_IN_UNIVERSE': 'T', 'FUND_OF_FUNDS': '', 'FUND_HOLDINGS_COUNT': '76', 'FUND_HOLDING_FUNDS_COUNT': '0'}
[ ]: