Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to convert Python Multiple list to list

By
priyankahdp
on 5/15/13, 8:51 AM 1,555 views

here is my python list when i debug it

list: [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]

now i need to convert it to this type list

list: [1,2,3,4,5]

please advice me to implement this.

2

Daniel Reis

--Daniel Reis--
3436
| 6 7 9
Lisbon, Portugal
--Daniel Reis--

Author of the "Odoo Development Essentials" book.

Applications Manager at Securitas Portugal

Github: https://github.com/dreispt

Twitter; @reis_pt


Daniel Reis
On 5/15/13, 3:10 PM

Why not use a one-liner?

>>> source = [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]
>>> result = [x[1] for x in source]
>>> print result
[1, 2, 3, 4, 5]

intelligent ! but for the visibility of code .!!

Borni DHIFI
on 5/15/13, 3:17 PM

thanks dear Daniel..seems its more easier :-)

priyankahdp
on 5/17/13, 1:02 AM
5

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 5/15/13, 9:04 AM

hey priyanka do one think :

 list=[[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]
 m=[]
 for i in range(0,len(list)):
     m.extend(list[0])
 m=[4, 1, False, 4, 2, False, 4, 3, False, 4, 4, False, 4, 5, False]

thanks

2

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 5/15/13, 9:01 AM

Hi;

list= [[4, 1, False], [4, 2, False], [4, 3, False], [4, 4, False], [4, 5, False]]      
my_list=[]
for object in list : 
    my_list.append(object[1])


print my_list # give [1, 2, 3, 4, 5]

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/15/13, 8:51 AM
Seen: 1555 times
Last updated: 3/16/15, 8:10 AM