-1

I have different variables of an unknown type (in ABAQUS, it says "Sequence") and want to combine them through a loop:

a = [[unknown type], [unknown type], ...]
x = []
for i in a:
    x.append(i)

The problem now is that when I initialize x with = [] I get the error message

TypeError: Can only concatenate list (not "Sequence") to list.

Is there another (simple/efficient) way, e.g. to automatically create x in the first loop?

user56574
  • 9
  • 5
  • 2
    You're looking for a [list comprehension](http://www.secnetix.de/olli/Python/list_comprehensions.hawk)... – Akshat Mahajan Apr 03 '16 at 23:07
  • That would assume `list` is the only type that has an `append` method; otherwise, how would Python know to assume `x = []`, rather than `x = SomeOtherThingWithAppend()`? – chepner Apr 03 '16 at 23:23

1 Answers1

2

Use a list comprehension:

x = [v for v in a]
idjaw
  • 25,487
  • 7
  • 64
  • 83