-1

Totally brand new to python.

if item['quoteAsset'] == 'TEST':
    arrayAsset = []
    arrayAsset.append(baseAsset)

How do I put the results into a proper list? At the moment this list only exists in position 0.

print(arrayAsset[0])

will print

['hello']
['test']
['kkk']
['abc']
['P11']

But, I want it in a proper list like shown below

["hello", "test", "kkk", "abc", "P11"]

Thanks

mrWiga
  • 131
  • 1
  • 2
  • 13
  • 4
    use `extend` arrayAsset.extend(baseAsset) – akash karothiya Jul 24 '18 at 11:45
  • 2
    Please [edit] your question and fix the indention of your Python code. –  Jul 24 '18 at 11:48
  • 1
    Possible duplicate of [Difference between append vs. extend list methods in Python](https://stackoverflow.com/questions/252703/difference-between-append-vs-extend-list-methods-in-python) – running.t Jul 24 '18 at 11:51
  • Please make this a [mcve]; your code as shown (minus possible indentation mishaps) cannot ever show the result you want. – Jongware Jul 24 '18 at 11:51
  • If I use extend, this is the results ['h, 'e', 'l', 'l', 'o'] ['t', 'e', 's', 't'] – mrWiga Jul 24 '18 at 11:55

2 Answers2

0

Try this -

arrayAsset = [] # define arrayAsset here
for item in some_collection: # I believe there is a for loop here
    if item['quoteAsset'] == 'TEST':
        arrayAsset.append(baseAsset)

But in your code -

if item['quoteAsset'] == 'TEST':
    arrayAsset = []  # you are declaring arrayAsset again and again when if condition is met
    arrayAsset.append(baseAsset)

So assign you list out of for loop and if condition so it does not get assigned again and again and you will end up with nothing but only single value, which is why At the moment this list only exists in position 0

Sushant
  • 3,499
  • 3
  • 17
  • 34
0

In List we have extend method it will append the another list in to the preset list try below code.

if item['quoteAsset'] == 'TEST':
    arrayAsset = []
    arrayAsset.extend(baseAsset)
venkat
  • 46
  • 1
  • 4