0

Example I have attributes as below:

a = [1,2,3]
b = [3,2,1]
r1 = 5
r2 = 6

How do I get:

foo = [1,2,3,3,2,1,5,6]
user3431399
  • 459
  • 3
  • 6
  • 19

3 Answers3

2

@falsetru As simple as:

foo = a + b + [r1, r2]
Aidan Gomez
  • 8,167
  • 5
  • 28
  • 51
1
def combine(*args):
    result = []
    for arg in args:
        if type(arg) is int:
            result.append(arg)
        elif type(arg) is list:
            result += arg
    return result
Hooting
  • 1,681
  • 11
  • 20
1

You have many options:

How @falsetru said:

foo = a + b + [r1] + [r2]

Or:

foot = []
foot.extend(a)
foot.extend(b)
foot.append(r1)
foot.append(r2)

Or:

foot = []
foot.extend(a)
foot.extend(b)
foot.extend([r1])
foot.extend([r2])

Or:

foot = []
foot.extend(a + b + [r1] + [r2])

You can know more about the lists here: Python Data Structures

Jose Moreno
  • 104
  • 4