-2

i have nth list of multiple element as shown below in func_name this is not a duplicate question because i found lot of answer where everylist is equal to some list name or list1, list2.... if you think it's a duplicate then please share the link with same question or tell me answer how i can write the output of func_name in a single list seperated with comma............

My inputs are shown below which are the outputs from func_name

xpcinitapi
xpcgetapiversion
xpcfreeapi
xpcregistertarget
xpcderegistertarget
xpcopenconnection
xpccloseconnection
xpcopentcpipport
xpccloseport
xpcreopenport
xpcreboot
xpctargetpingapi
xpcgettargetversion
xpcloadapp
xpcunloadapp
xpcisapprunning
xpcsetecho
xpcgetecho
xpcsetloadtimeout
xpcgetloadtimeout
xpcgetappname
xpcstartapp
xpcstopapp
xpcsetsampletime
xpcgetsampletime
xpcsetstoptime
xpcgetstoptime
xpcaveragetet
xpcgetexectime
xpcgetsessiontime
xpcisapprunning
xpcisoverloaded
xpcmaximumtet
xpcminimumtet
xpcsaveparamset
xpcloadparamset
xpcerrormsg
xpcgetlasterror
xpcsetlasterror
xpcsetlasterror
xpcaddscope
xpcsetscope
xpcremscope
xpcgetnumscopes
xpcgetscope
xpcgetscopelist
xpcgetscopes
xpcscaddsignal
xpcscremsignal
xpcscgetnumsignals

i want to combine all these list element or inputs in a single list seperated by comma
i tried to use append but i'm getting same list and i want to combine all element in a signle list

    def duplicate(func_name):
        aa = (func_name.splitlines(1))
        words = []
        for i in aa:
            words.append(i)


        return (words)

can any one please tell me how can i combine them like a single list to get the following output

    output = ['xpcinitapi', 'xpcgetapiversion','xpcfreeapi' and so on....] 

thank you
  • to be more accurate: "This question has been asked 56700 times before and already has 20 answers" – Jean-François Fabre Jul 12 '17 at 08:59
  • @Jean-FrançoisFabre can you please share only a single link where i can find same question – siddiqui_902003 Jul 12 '17 at 09:19
  • now that you have edited, I think that the duplicate link isn't the correct one yes, but the question is still unclear. Can you trim down your question with inputs & expected outputs python-style? like a [mcve]. "I put that as input, I get that as output, but I want that". Then I'll reopen or put the proper duplicate, no problem. @siddiqui_902003 – Jean-François Fabre Jul 12 '17 at 09:33
  • So, again, what I want is a complete piece of *code* that, when copy-pasted, *reproduces* the error. I simply don't understand what you're trying to ask. – klutt Jul 12 '17 at 09:35
  • We're still missing code from func_name... – klutt Jul 12 '17 at 09:46
  • I found the answer Thank you – siddiqui_902003 Jul 12 '17 at 10:11

2 Answers2

0
>>> A = [['a'],['b'],['c']]
>>> B = [b[0] for b in A] 
>>> B
['a', 'b', 'c']
klutt
  • 30,332
  • 17
  • 55
  • 95
  • 1
    please refrain from answering duplicate questions as it makes them harder to delete – WhatsThePoint Jul 12 '17 at 08:54
  • It was not marked as a dup when I answered. – klutt Jul 12 '17 at 08:55
  • @klutt how did you creat A....??? I have nth list of element and i can't write all them equal to A – siddiqui_902003 Jul 12 '17 at 08:56
  • I marked as duplicate too late. But the answer is very weak compared to the 20 answers of the duplicate. – Jean-François Fabre Jul 12 '17 at 08:58
  • Please look in the linked answer. If it does not answer your question, edit this question and explain why it's not a duplicate. Also, read about how to make a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – klutt Jul 12 '17 at 08:59
  • tell me the answer how i combine all these list seperated with comma – siddiqui_902003 Jul 12 '17 at 09:00
  • @klutt it's not duplicate because i don't have a structure like list_1 = ['a'] did you get now my point – siddiqui_902003 Jul 12 '17 at 09:03
  • Then again, please read how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). Your post is not clear. It should preferably be so that I can just copy-paste your code into an editor and run it. – klutt Jul 12 '17 at 09:07
  • That is, you have described what output you want, which is great. What I'm missing is the current output and *complete* code to reproduce that output. – klutt Jul 12 '17 at 09:09
0

you can use chain from itertools

>>> list(chain.from_iterable([['a'],['b']]))
['a', 'b']
Rahul
  • 10,830
  • 4
  • 53
  • 88
  • you did not get the question – siddiqui_902003 Jul 12 '17 at 08:57
  • You rather didn't asked it that way. – Rahul Jul 12 '17 at 08:58
  • @siddiqui_902003 np.array answer is one way to do it. we cannot spoon feed the answer for you. Please make some effort, at least read & try the solutions. – Jean-François Fabre Jul 12 '17 at 09:02
  • @ Jean-François Fabre i tried to solve but i can't that's why i post here np.array answer is not acceptable for me because he just write two list and combine them but i have more than 100 list with one element in each and they are not in format like list1 = ['a'] and list2 = ['b'] – siddiqui_902003 Jul 12 '17 at 09:09