-2

I want to make an insert on the List Comprehensions. I can do it?

t = ['test','tes']
x = ['1','2','3','4','5']
t.insert([0,i]for i in x)
Avihoo Mamka
  • 4,656
  • 3
  • 31
  • 44

4 Answers4

1

If the result you're looking for is something like this

['test', 'tes', [0, 'test'], [0, 'tes']]

The code is below:

t = ['test','tes']
x = ['1','2','3','4','5']
t.extend([[0,i]for i in t])

print t
XPLOT1ON
  • 2,994
  • 2
  • 20
  • 36
1

You can do it in a list comprehension but it ends up doing extra work. Just do it in a for loop:

for thing in x:
    t.insert(0, thing)
wwii
  • 23,232
  • 7
  • 37
  • 77
0
t = ['test','tes']
x = ['1','2','3','4','5']
out = t + x

your out put will be ['tes','test','1','2','3','4','5','6'] or something alone those lines. python allows you to concatenate strings

ttallierchio
  • 460
  • 7
  • 17
0

The ListItemLabel accepts only strings. I want to give it more than one element in a list, I use in ListItemLabel front str, but it does not do anything.

I do not know if it's the way you think

Python:

result_true = ListProperty([])

extra = self.viewedit.adapter.data 

for edit in extra: 
   if edit['active'] == True:

    app.result_true.append(edit['text'])
    #app.result_true = (edit['text'])
    print app.result_true 

Kivy:

ListItemLabel:
text:str(ctx.edit)

Return:

['\xce\xbb\xce\xb9\xce\xb1\xcf\x83\xcf\x84\xce\xae \xce\xbd\xcf\x84\xce\xbf\xce\xbc\xce\xac\xcf\x84\xce\xb1', '\xcf\x83\xce\xbf\xcf\x85\xcf\x83\xce\xac\xce\xbc\xce\xb9', '\xcf\x84\xcf\x85\xcf\x81\xce\xaf']