0

I need some help with a fuction. I have multiple lists called 'info' that are displayed as follows in a single textfile:

[['a', 'b', 'c'],['d1','e2','f2'],['g','h','i']]
[['test', 'test1', 'test2']['test3', 'test4', 'test5']['test6', 'test7', 'test8']]

I am trying to write a function that changes all triplets into one string and then loops through all the triples in the list to change them. Output should be:

['a b c','d1 e2 f2','g h i']
['test test1 test2','test3 test4 test5','test6 test7 test8']

I am trying things such as:

def short(x)
if len(x) == 3
    ' ' .join(x)

And then I have to do something to loop trough the list and check the parameters. I've been trying things such as:

def check (y)
param=info[0] 
short(param)

and trying with for statements

But I'm getting nowhere...

Provided answer does not help at all. It just shows the same things that I've been trying

Sjoerd1234
  • 148
  • 1
  • 2
  • 11
  • 1
    Shouldn't `'d e f'` be `'d1 e2 f2'`? – Ajax1234 Sep 08 '18 at 22:47
  • 1
    `return [' '.join(i) for i in x if len(i)==3]` – David Zemens Sep 08 '18 at 22:50
  • Ajax1234, yes my bad – Sjoerd1234 Sep 08 '18 at 22:51
  • *Provided answer does not help at all. It just shows the same things that I've been trying* but you haven't really shown us what you've tried, you've just tossed out a few lines of code that won't compile (indentation matters). Your question has been closed because based on the few details shared it is similar enough that the scope of the problem (combining strings from a sequence/list) is addressed by the other answer. – David Zemens Sep 09 '18 at 01:19
  • If you have a specific problem with code implementation, see [ask] and consider including a [mcve] before asking new question. (You'll need to ask a new one, closed questions are rarely re-opened.) Anticipate what others will ask: are inputs *always* sequences of 3? Inputs always string? You've indicated what you want to accomplish: *I am trying to write a function...* but you haven't actually demonstrated any of that, so it is difficult to provide direct guidance since it's unclear what your problem(s) really is. – David Zemens Sep 09 '18 at 01:23
  • My coding skills are not well and I'm trying desperately to accomplish the task. I spend already 7+ hours searching trough for statements, if statements, len(x), .join python documentation and other threads to accomplish this single function. This was a last attempt of figuring out. for it to be swept away like that was not motivating. I want to learn, people don't have to give the answer but even a nudge would help – Sjoerd1234 Sep 09 '18 at 10:34
  • If you want to learn, then you should be willing to put in the time to [ask](https://stackoverflow.com/questions/how-to-ask) a good question. Provide code samples that compile, inputs, expected outputs, and description of specific errors/failures. *And then I have to do something to loop trough the list and check the parameters*. Nobody understands what this means, and the code below it doesn't compile, so it's hard to even guess. *and trying with for statements* also, makes no sense. *what* have you tried? Show us. Show us what's wrong with it. Then maybe we can help. – David Zemens Sep 10 '18 at 12:53

0 Answers0