How can I get this result?

27 views
Skip to first unread message

aroni...@gmail.com

unread,
Feb 15, 2015, 4:56:25 AM2/15/15
to django...@googlegroups.com
[{'key1':a , 'key2': b},{'key1':c , 'key2': d}]
a,b
c,d

Shai Efrati

unread,
Feb 15, 2015, 9:27:11 AM2/15/15
to django...@googlegroups.com
assuming:
l = [{'key1':a , 'key2': b},{'key1':c , 'key2': d}]

for e in l:
for k, v in iteritems(e):
print v,
print
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/90d2e6f3-ed06-40f3-a6cd-29e895504710%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Shai Efrati

unread,
Feb 15, 2015, 9:30:52 AM2/15/15
to django...@googlegroups.com
sorry.
assuming:
l = [{'key1':'a' , 'key2': 'b'},{'key1':'c' , 'key2': 'd'}]

for e in l:
for k, v in e.iteritems():
print v,
print

Krishnasagar Subhedarpage

unread,
Feb 15, 2015, 10:33:38 AM2/15/15
to django...@googlegroups.com
Hi,

consider two objects, 
ls_dic=[{'key1':a , 'key2': b},{'key1':c , 'key2': d}]
num=sum([len(x.values()) for x in ls_dic])

print '%s' % ','.join(sorted(sum([x.values() for x in ls_dic],[])))[:-num]
print '%s' % ','.join(sorted(sum([x.values() for x in ls_dic],[])))[num:]

This is will help a lot. 
ls_dic list object is considered for input. I used num object to store number of values in each directory item of ls_dic list. This object is used in further 2 print statements. These statements will print in expected output fashion. Check it out.


Enjoy!!!!! 
 



For more options, visit https://groups.google.com/d/optout.



--
Krishnasagar S. Subhedarpage
India
Reply all
Reply to author
Forward
0 new messages