Re: What iterable method should I use for Lists of Lists

2016-04-18 Thread Peter Otten
Sayth Renshaw wrote:

> Think I have a solution of sorts, although my numpy array failed, zip
> worked.
> 
> from pyquery import PyQuery as pq
> import numpy as np
> 
> d = pq(filename='20160319RHIL0_edit.xml')
> res = d('nomination')
> # myAt = pq.each(res.attr('bbid'))
> # print(repr(res))
> # myAt = [res.eq(i).attr('horse') for i in range(len(res))]
> # print(myAt)
> 
> nomID = [res.eq(i).attr('id') for i in range(len(res))]
> horseName = [res.eq(i).attr('horse') for i in range(len(res))]
> zipped = zip(nomID, horseName)
> 
> # yes = np.array(zipped)
> for items in zipped:
> print(items)
> 
> In [8]: ('171115', 'Vergara')
> ('187674', 'Heavens Above')
> ('184732', 'Sweet Fire')
> ('181928', 'Alegria')
> ('158914', 'Piamimi')
> ('171408', 'Blendwell')
> ('166836', 'Adorabeel (NZ)')
> ('172933', 'Mary Lou')
> ('182533', 'Skyline Blush')
> ('171801', 'All Cerise')
> ('181079', 'Gust of Wind (NZ)')
> 
> Still interested if there is a better to do this.

I don't know pyquery, so there may still be better ways. This is how far I 
got with dir() and the common Python wisdom "Never use range(len(...))":

>>> import pyquery
>>> d = pyquery.PyQuery(filename="horse.xml")
>>> pairs = [(n.attrib["horse"], n.attrib["id"]) for n in d("nomination")]
>>> import pprint
>>> pprint.pprint(pairs)
[('Vergara', '171115'),
 ('Heavens Above', '187674'),
 ('Sweet Fire', '184732'),
 ('Alegria', '181928'),
 ('Piamimi', '158914'),
 ('Blendwell', '171408'),
 ('Adorabeel (NZ)', '166836'),
 ('Mary Lou', '172933'),
 ('Skyline Blush', '182533'),
 ('All Cerise', '171801'),
 ('Gust of Wind (NZ)', '181079')]

pprint is not really necessary, it just gives more readable output than

>>> pairs
[('Vergara', '171115'), ('Heavens Above', '187674'), ('Sweet Fire', 
'184732'), ('Alegria', '181928'), ('Piamimi', '158914'), ('Blendwell', 
'171408'), ('Adorabeel (NZ)', '166836'), ('Mary Lou', '172933'), ('Skyline 
Blush', '182533'), ('All Cerise', '171801'), ('Gust of Wind (NZ)', 
'181079')]

To extract more than one attribute operator.itemgetter comes in handy:

>>> from operator import itemgetter
>>> get = itemgetter("horse", "id", "saddlecloth")
>>> pprint.pprint([get(n.attrib) for n in d("nomination")])
[('Vergara', '171115', '4'),
 ('Heavens Above', '187674', '2'),
 ('Sweet Fire', '184732', '6'),
 ('Alegria', '181928', '7'),
 ('Piamimi', '158914', '11'),
 ('Blendwell', '171408', '10'),
 ('Adorabeel (NZ)', '166836', '3'),
 ('Mary Lou', '172933', '8'),
 ('Skyline Blush', '182533', '9'),
 ('All Cerise', '171801', '5'),
 ('Gust of Wind (NZ)', '181079', '1')]

If you need to do some post-processing use a helper function:

>>> def extract(n):
... attrib = n.attrib
... id = int(attrib["id"])
... name = attrib["horse"].upper()
... return id, name
... 
>>> pprint.pprint([extract(n) for n in d("nomination")])
[(171115, 'VERGARA'),
 (187674, 'HEAVENS ABOVE'),
 (184732, 'SWEET FIRE'),
 (181928, 'ALEGRIA'),
 (158914, 'PIAMIMI'),
 (171408, 'BLENDWELL'),
 (166836, 'ADORABEEL (NZ)'),
 (172933, 'MARY LOU'),
 (182533, 'SKYLINE BLUSH'),
 (171801, 'ALL CERISE'),
 (181079, 'GUST OF WIND (NZ)')]


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What iterable method should I use for Lists of Lists

2016-04-18 Thread Sayth Renshaw

> 
> You're getting very chatty with yourself, which is fine... but do you
> need to quote your entire previous message every time? We really don't
> need another copy of your XML file in every post.
> 
> Thanks!
> 
> ChrisA

Oops sorry, everytime I posted I then thought of another resource and kept 
reading.

I have a working messy solution hopefully I can resolve it to something nicer.

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What iterable method should I use for Lists of Lists

2016-04-17 Thread Chris Angelico
On Mon, Apr 18, 2016 at 2:09 PM, Sayth Renshaw  wrote:
>> > > > > > id="187674" idnumber="" regnumber="" blinkers="0" trainernumber="736" 
>> > > trainersurname="Martin" trainerfirstname="Tim" trainertrack="Rosehill" 
>> > > rsbtrainername="Tim Martin" jockeynumber="46930" jockeysurname="Angland" 
>> > > jockeyfirstname="Tye" barrier="6" weight="56" rating="88" description="B 
>> > > M 4 Street Cry(IRE) x Reggie(NZ) (Germano(GB))" colours="Yellow, Green 
>> > > Chevrons, Striped Cap" owners="President Bloodstock Pty Ltd (Mgr: R C 
>> > > Kemister)" dob="2011-08-12T00:00:00" age="5" sex="M" career="12-3-3-4 
>> > > $271520.00" thistrack="4-0-3-0 $41425.00" thisdistance="0-0-0-0" 
>> > > goodtrack="10-2-2-4 $214845.00" heavytrack="0-0-0-0" slowtrack="" 
>> > > deadtrack="" fasttrack="0-0-0-0" firstup="2-0-1-1 $20710.00" 
>> > > secondup="2-0-2-0 $24675.00" mindistancewin="0" maxdistancewin="0" 
>> > > finished="2" weightvariation="0" variedweight="56" decimalmargin="0.20" 
>> > > penalty="0" pricestarting="$3.80F" sectional200="0" sectional400="0" 
>> > > sectional600="0" sectional80
 0
>  ="0" sectional1200="0" bonusindicator="" />

You're getting very chatty with yourself, which is fine... but do you
need to quote your entire previous message every time? We really don't
need another copy of your XML file in every post.

Thanks!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What iterable method should I use for Lists of Lists

2016-04-17 Thread Sayth Renshaw
On Monday, 18 April 2016 13:13:21 UTC+10, Sayth Renshaw  wrote:
> On Monday, 18 April 2016 12:12:59 UTC+10, Sayth Renshaw  wrote:
> > On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw  wrote:
> > > Hi
> > > 
> > > I have an XML and using pyquery to obtain the elements within it and then 
> > > write it to csv.
> > > 
> > > What is the best most reliable way to take dictionaries of each element, 
> > > and print them(csv write later) based on each position so get item 0 of 
> > > each list and then it 1 and so on.
> > > 
> > > Any other code I post is open to criticism. Because there are many 
> > > attributes I will want to collect my thought is to create a list of 
> > > lists, again seems a bit clunky so could be wrong.
> > > 
> > > from pyquery import PyQuery as pq
> > > 
> > > 
> > > d = pq(filename='20160319RHIL0_edit.xml')
> > > res = d('nomination')
> > > # myAt = pq.each(res.attr('bbid'))
> > > # print(repr(res))
> > > # myAt = [res.eq(i).attr('horse') for i in range(len(res))]
> > > # print(myAt)
> > > 
> > > nomID = [res.eq(i).attr('horse') for i in range(len(res))]
> > > horseName = [res.eq(i).attr('horse') for i in range(len(res))]
> > > group = [nomID, horseName]
> > > 
> > > for items in group:
> > > print(items)
> > > 
> > > 
> > > This is my source.
> > > 
> > > 
> > >  > > date="2016-03-19T00:00:00" gearchanges="-1" stewardsreport="-1" 
> > > gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB" 
> > > rail="Timing - Electronic : Rail - +2m" weather="Fine  " 
> > > trackcondition="Good" nomsdeadline="2016-03-14T11:00:00" 
> > > weightsdeadline="2016-03-15T16:00:00" 
> > > acceptdeadline="2016-03-16T09:00:00" jockeydeadline="2016-03-16T12:00:00">
> > >> > associationclass="1" website="http://; />
> > >> > stage="Results" distance="1900" minweight="0" raisedweight="0" class="~   
> > >   " age="3U" grade="0" weightcondition="SWP   " 
> > > trophy="1000" owner="1000" trainer="0" jockey="0" strapper="0" 
> > > totalprize="15" first="9" second="3" third="15000" 
> > > fourth="7500" fifth="3000" time="2016-03-19T12:40:00" bonustype=" 
> > >  " nomsfee="0" acceptfee="0" trackcondition="Good  " 
> > > timingmethod="Electronic" fastesttime="1-56.83   " 
> > > sectionaltime="600/35.3  " formavailable="0" racebookprize="Of $15 
> > > and trophies of $1000. First $9 and trophies of $1000 to owner, 
> > > second $3, third $15000, fourth $7500, fifth $3000, sixth $1500, 
> > > seventh $1500, eighth $1500">
> > > Of $15 and trophies of $1000. First $9 
> > > and trophies of $1000 to owner, second $3, third $15000, fourth 
> > > $7500, fifth $3000, sixth $1500, seventh $1500, eighth $1500
> > > No class restriction, Set Weights plus Penalties, 
> > > For Three-Years-Old and Upwards, Fillies and Mares, (Group 3)
> > > No Allowances for apprentices. Field Limit: 14 + 
> > > 4 EM
> > >  > > idnumber="" regnumber="" blinkers="1" trainernumber="38701" 
> > > trainersurname="Cummings" trainerfirstname="Anthony" 
> > > trainertrack="Randwick" rsbtrainername="Anthony Cummings" 
> > > jockeynumber="86876" jockeysurname="McDonald" jockeyfirstname="James" 
> > > barrier="7" weight="55" rating="93" description="B M 5 Snippetson x 
> > > Graces Spirit (Flying Spur)" colours="Yellow, Red Epaulettes And Cap" 
> > > owners="Anthony Cummings Thoroughbreds Pty Ltd Syndicate (Mgrs: A  B 
> > > Cummings)  P C Racing Investments Syndicate (Mgr: P J Carroll)  " 
> > > dob="2010-10-07T00:00:00" age="6" sex="M" career="30-7-4-2 $295445.00" 
> > > thistrack="6-1-1-0 $90500.00" thisdistance="0-0-0-0" goodtrack="17-3-2-2 
> > > $101440.00" heavytrack="5-0-1-0 $20200.00" slowtrack="" deadtrack="" 
> > > fasttrack="0-0-0-0" firstup="7-2-1-2 $108340.00" secondup="7-1-1-0 
> > > $43200.00" mindistancewin="0" maxdistancewin="0" finished="1" 
> > > weightvariation="0" variedweight="55" decimalmargin="0.
 00" penalty="0" pricestarting="$12" sectional200="0" sectional400="0" 
sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
> > >  > > id="187674" idnumber="" regnumber="" blinkers="0" trainernumber="736" 
> > > trainersurname="Martin" trainerfirstname="Tim" trainertrack="Rosehill" 
> > > rsbtrainername="Tim Martin" jockeynumber="46930" jockeysurname="Angland" 
> > > jockeyfirstname="Tye" barrier="6" weight="56" rating="88" description="B 
> > > M 4 Street Cry(IRE) x Reggie(NZ) (Germano(GB))" colours="Yellow, Green 
> > > Chevrons, Striped Cap" owners="President Bloodstock Pty Ltd (Mgr: R C 
> > > Kemister)" dob="2011-08-12T00:00:00" age="5" sex="M" career="12-3-3-4 
> > > $271520.00" thistrack="4-0-3-0 $41425.00" thisdistance="0-0-0-0" 
> > > goodtrack="10-2-2-4 $214845.00" heavytrack="0-0-0-0" slowtrack="" 
> > > deadtrack="" fasttrack="0-0-0-0" firstup="2-0-1-1 $20710.00" 
> > > secondup="2-0-2-0 $24675.00" mindistancewin="0" maxdistancewin="0" 
> > > finished="2" weightvariation="0" 

Re: What iterable method should I use for Lists of Lists

2016-04-17 Thread Sayth Renshaw
On Monday, 18 April 2016 12:12:59 UTC+10, Sayth Renshaw  wrote:
> On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw  wrote:
> > Hi
> > 
> > I have an XML and using pyquery to obtain the elements within it and then 
> > write it to csv.
> > 
> > What is the best most reliable way to take dictionaries of each element, 
> > and print them(csv write later) based on each position so get item 0 of 
> > each list and then it 1 and so on.
> > 
> > Any other code I post is open to criticism. Because there are many 
> > attributes I will want to collect my thought is to create a list of lists, 
> > again seems a bit clunky so could be wrong.
> > 
> > from pyquery import PyQuery as pq
> > 
> > 
> > d = pq(filename='20160319RHIL0_edit.xml')
> > res = d('nomination')
> > # myAt = pq.each(res.attr('bbid'))
> > # print(repr(res))
> > # myAt = [res.eq(i).attr('horse') for i in range(len(res))]
> > # print(myAt)
> > 
> > nomID = [res.eq(i).attr('horse') for i in range(len(res))]
> > horseName = [res.eq(i).attr('horse') for i in range(len(res))]
> > group = [nomID, horseName]
> > 
> > for items in group:
> > print(items)
> > 
> > 
> > This is my source.
> > 
> > 
> >  > date="2016-03-19T00:00:00" gearchanges="-1" stewardsreport="-1" 
> > gearlist="-1" racebook="0" postracestewards="0" meetingtype="TAB" 
> > rail="Timing - Electronic : Rail - +2m" weather="Fine  " 
> > trackcondition="Good" nomsdeadline="2016-03-14T11:00:00" 
> > weightsdeadline="2016-03-15T16:00:00" acceptdeadline="2016-03-16T09:00:00" 
> > jockeydeadline="2016-03-16T12:00:00">
> >> website="http://; />
> >> stage="Results" distance="1900" minweight="0" raisedweight="0" class="~ 
> > " age="3U" grade="0" weightcondition="SWP   " trophy="1000" 
> > owner="1000" trainer="0" jockey="0" strapper="0" totalprize="15" 
> > first="9" second="3" third="15000" fourth="7500" fifth="3000" 
> > time="2016-03-19T12:40:00" bonustype="  " nomsfee="0" acceptfee="0" 
> > trackcondition="Good  " timingmethod="Electronic" fastesttime="1-56.83  
> >  " sectionaltime="600/35.3  " formavailable="0" racebookprize="Of $15 
> > and trophies of $1000. First $9 and trophies of $1000 to owner, second 
> > $3, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh 
> > $1500, eighth $1500">
> > Of $15 and trophies of $1000. First $9 and 
> > trophies of $1000 to owner, second $3, third $15000, fourth $7500, 
> > fifth $3000, sixth $1500, seventh $1500, eighth $1500
> > No class restriction, Set Weights plus Penalties, 
> > For Three-Years-Old and Upwards, Fillies and Mares, (Group 3)
> > No Allowances for apprentices. Field Limit: 14 + 4 
> > EM
> >  > idnumber="" regnumber="" blinkers="1" trainernumber="38701" 
> > trainersurname="Cummings" trainerfirstname="Anthony" 
> > trainertrack="Randwick" rsbtrainername="Anthony Cummings" 
> > jockeynumber="86876" jockeysurname="McDonald" jockeyfirstname="James" 
> > barrier="7" weight="55" rating="93" description="B M 5 Snippetson x Graces 
> > Spirit (Flying Spur)" colours="Yellow, Red Epaulettes And Cap" 
> > owners="Anthony Cummings Thoroughbreds Pty Ltd Syndicate (Mgrs: A  B 
> > Cummings)  P C Racing Investments Syndicate (Mgr: P J Carroll)  " 
> > dob="2010-10-07T00:00:00" age="6" sex="M" career="30-7-4-2 $295445.00" 
> > thistrack="6-1-1-0 $90500.00" thisdistance="0-0-0-0" goodtrack="17-3-2-2 
> > $101440.00" heavytrack="5-0-1-0 $20200.00" slowtrack="" deadtrack="" 
> > fasttrack="0-0-0-0" firstup="7-2-1-2 $108340.00" secondup="7-1-1-0 
> > $43200.00" mindistancewin="0" maxdistancewin="0" finished="1" 
> > weightvariation="0" variedweight="55" decimalmargin="0.00
 " penalty="0" pricestarting="$12" sectional200="0" sectional400="0" 
sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
> >  > id="187674" idnumber="" regnumber="" blinkers="0" trainernumber="736" 
> > trainersurname="Martin" trainerfirstname="Tim" trainertrack="Rosehill" 
> > rsbtrainername="Tim Martin" jockeynumber="46930" jockeysurname="Angland" 
> > jockeyfirstname="Tye" barrier="6" weight="56" rating="88" description="B M 
> > 4 Street Cry(IRE) x Reggie(NZ) (Germano(GB))" colours="Yellow, Green 
> > Chevrons, Striped Cap" owners="President Bloodstock Pty Ltd (Mgr: R C 
> > Kemister)" dob="2011-08-12T00:00:00" age="5" sex="M" career="12-3-3-4 
> > $271520.00" thistrack="4-0-3-0 $41425.00" thisdistance="0-0-0-0" 
> > goodtrack="10-2-2-4 $214845.00" heavytrack="0-0-0-0" slowtrack="" 
> > deadtrack="" fasttrack="0-0-0-0" firstup="2-0-1-1 $20710.00" 
> > secondup="2-0-2-0 $24675.00" mindistancewin="0" maxdistancewin="0" 
> > finished="2" weightvariation="0" variedweight="56" decimalmargin="0.20" 
> > penalty="0" pricestarting="$3.80F" sectional200="0" sectional400="0" 
> > sectional600="0" sectional800="
 0" sectional1200="0" bonusindicator="" />
> >  > idnumber="" regnumber="" blinkers="0" trainernumber="681" 
> > 

Re: What iterable method should I use for Lists of Lists

2016-04-17 Thread Sayth Renshaw
On Monday, 18 April 2016 12:05:39 UTC+10, Sayth Renshaw  wrote:
> Hi
> 
> I have an XML and using pyquery to obtain the elements within it and then 
> write it to csv.
> 
> What is the best most reliable way to take dictionaries of each element, and 
> print them(csv write later) based on each position so get item 0 of each list 
> and then it 1 and so on.
> 
> Any other code I post is open to criticism. Because there are many attributes 
> I will want to collect my thought is to create a list of lists, again seems a 
> bit clunky so could be wrong.
> 
> from pyquery import PyQuery as pq
> 
> 
> d = pq(filename='20160319RHIL0_edit.xml')
> res = d('nomination')
> # myAt = pq.each(res.attr('bbid'))
> # print(repr(res))
> # myAt = [res.eq(i).attr('horse') for i in range(len(res))]
> # print(myAt)
> 
> nomID = [res.eq(i).attr('horse') for i in range(len(res))]
> horseName = [res.eq(i).attr('horse') for i in range(len(res))]
> group = [nomID, horseName]
> 
> for items in group:
> print(items)
> 
> 
> This is my source.
> 
> 
>  date="2016-03-19T00:00:00" gearchanges="-1" stewardsreport="-1" gearlist="-1" 
> racebook="0" postracestewards="0" meetingtype="TAB" rail="Timing - Electronic 
> : Rail - +2m" weather="Fine  " trackcondition="Good" 
> nomsdeadline="2016-03-14T11:00:00" weightsdeadline="2016-03-15T16:00:00" 
> acceptdeadline="2016-03-16T09:00:00" jockeydeadline="2016-03-16T12:00:00">
>website="http://; />
>stage="Results" distance="1900" minweight="0" raisedweight="0" class="~   
>   " age="3U" grade="0" weightcondition="SWP   " trophy="1000" 
> owner="1000" trainer="0" jockey="0" strapper="0" totalprize="15" 
> first="9" second="3" third="15000" fourth="7500" fifth="3000" 
> time="2016-03-19T12:40:00" bonustype="  " nomsfee="0" acceptfee="0" 
> trackcondition="Good  " timingmethod="Electronic" fastesttime="1-56.83   
> " sectionaltime="600/35.3  " formavailable="0" racebookprize="Of $15 and 
> trophies of $1000. First $9 and trophies of $1000 to owner, second 
> $3, third $15000, fourth $7500, fifth $3000, sixth $1500, seventh $1500, 
> eighth $1500">
> Of $15 and trophies of $1000. First $9 and 
> trophies of $1000 to owner, second $3, third $15000, fourth $7500, fifth 
> $3000, sixth $1500, seventh $1500, eighth $1500
> No class restriction, Set Weights plus Penalties, For 
> Three-Years-Old and Upwards, Fillies and Mares, (Group 3)
> No Allowances for apprentices. Field Limit: 14 + 4 
> EM
>  idnumber="" regnumber="" blinkers="1" trainernumber="38701" 
> trainersurname="Cummings" trainerfirstname="Anthony" trainertrack="Randwick" 
> rsbtrainername="Anthony Cummings" jockeynumber="86876" 
> jockeysurname="McDonald" jockeyfirstname="James" barrier="7" weight="55" 
> rating="93" description="B M 5 Snippetson x Graces Spirit (Flying Spur)" 
> colours="Yellow, Red Epaulettes And Cap" owners="Anthony Cummings 
> Thoroughbreds Pty Ltd Syndicate (Mgrs: A  B Cummings)  P C Racing 
> Investments Syndicate (Mgr: P J Carroll)  " dob="2010-10-07T00:00:00" age="6" 
> sex="M" career="30-7-4-2 $295445.00" thistrack="6-1-1-0 $90500.00" 
> thisdistance="0-0-0-0" goodtrack="17-3-2-2 $101440.00" heavytrack="5-0-1-0 
> $20200.00" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="7-2-1-2 
> $108340.00" secondup="7-1-1-0 $43200.00" mindistancewin="0" 
> maxdistancewin="0" finished="1" weightvariation="0" variedweight="55" 
> decimalmargin="0.00" 
 penalty="0" pricestarting="$12" sectional200="0" sectional400="0" 
sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
>  idnumber="" regnumber="" blinkers="0" trainernumber="736" 
> trainersurname="Martin" trainerfirstname="Tim" trainertrack="Rosehill" 
> rsbtrainername="Tim Martin" jockeynumber="46930" jockeysurname="Angland" 
> jockeyfirstname="Tye" barrier="6" weight="56" rating="88" description="B M 4 
> Street Cry(IRE) x Reggie(NZ) (Germano(GB))" colours="Yellow, Green Chevrons, 
> Striped Cap" owners="President Bloodstock Pty Ltd (Mgr: R C Kemister)" 
> dob="2011-08-12T00:00:00" age="5" sex="M" career="12-3-3-4 $271520.00" 
> thistrack="4-0-3-0 $41425.00" thisdistance="0-0-0-0" goodtrack="10-2-2-4 
> $214845.00" heavytrack="0-0-0-0" slowtrack="" deadtrack="" 
> fasttrack="0-0-0-0" firstup="2-0-1-1 $20710.00" secondup="2-0-2-0 $24675.00" 
> mindistancewin="0" maxdistancewin="0" finished="2" weightvariation="0" 
> variedweight="56" decimalmargin="0.20" penalty="0" pricestarting="$3.80F" 
> sectional200="0" sectional400="0" sectional600="0" sectional800="0"
  sectional1200="0" bonusindicator="" />
>  idnumber="" regnumber="" blinkers="0" trainernumber="681" 
> trainersurname="Waller" trainerfirstname="Chris" trainertrack="Rosehill" 
> rsbtrainername="Chris Waller" jockeynumber="51661" jockeysurname="Berry" 
> jockeyfirstname="Tommy" barrier="5" weight="54" rating="85" description="BR M 
> 4 Shamardal(USA) x Zarinia(IRE) (Intikhab(USA))" 

What iterable method should I use for Lists of Lists

2016-04-17 Thread Sayth Renshaw
Hi

I have an XML and using pyquery to obtain the elements within it and then write 
it to csv.

What is the best most reliable way to take dictionaries of each element, and 
print them(csv write later) based on each position so get item 0 of each list 
and then it 1 and so on.

Any other code I post is open to criticism. Because there are many attributes I 
will want to collect my thought is to create a list of lists, again seems a bit 
clunky so could be wrong.

from pyquery import PyQuery as pq


d = pq(filename='20160319RHIL0_edit.xml')
res = d('nomination')
# myAt = pq.each(res.attr('bbid'))
# print(repr(res))
# myAt = [res.eq(i).attr('horse') for i in range(len(res))]
# print(myAt)

nomID = [res.eq(i).attr('horse') for i in range(len(res))]
horseName = [res.eq(i).attr('horse') for i in range(len(res))]
group = [nomID, horseName]

for items in group:
print(items)


This is my source.



  http://; />
  
Of $15 and trophies of $1000. First $9 and 
trophies of $1000 to owner, second $3, third $15000, fourth $7500, fifth 
$3000, sixth $1500, seventh $1500, eighth $1500
No class restriction, Set Weights plus Penalties, For 
Three-Years-Old and Upwards, Fillies and Mares, (Group 3)
No Allowances for apprentices. Field Limit: 14 + 4 
EM











  


If I do this


nomID = [res.eq(i).attr('horse') for i in range(len(res))]
horseName = [res.eq(i).attr('horse') for i in range(len(res))]
print(nomID, horseName)

comes out correctly

In [7]: 171115 Vergara

Since I will be taking another 10 attributes out of nominmation category an 
efficient way that ensures data integrity would be valued.

Thanks

Sayth 

-- 
https://mail.python.org/mailman/listinfo/python-list