-5

i have a list of float and i want place in a container and get the values without brackets

tt1= [102, 0.5, 0.591, 0.529, 10, 42, 26, 6, 8, 17, 24]

container = solution in my problem

expected result simply

102, 0.5, 0.591, 0.529, 10, 42, 26, 6, 8, 17, 24

i've try some other solution but it turn to string which is not good cause i need it in float e.g

In [1]:','.join( str(a) for a in tt1 )
Out[1]: '102,0.5,0.591,0.529,10,42,26,6,8,17,24'

plss help

QWERTY
  • 3
  • 3
  • 2
    isnt that the whole point of a list though? If you need to do any calculations on any item, why cant you use the list? And if you need to display it or write to a file, that has to be done in strings, so what's the issue there? – Paritosh Singh Feb 18 '19 at 10:54
  • 1
    What exactly do you mean by "without brackets"? The brackets do not actually exist in a list, they are just part of the syntax to define a list literal in code and to print the list. Do you just want to *print* the list without the brackets? – Rory Daulton Feb 18 '19 at 10:55
  • Possible duplicate of [Pythonic way to print list items](https://stackoverflow.com/questions/15769246/pythonic-way-to-print-list-items) – Jack Moody Feb 18 '19 at 10:57
  • `repr(tt1)[1:-1]` perhaps? – Zulfiqaar Feb 18 '19 at 11:01
  • 1
    this is really what i want to do. i want to add tt1 in another list but the thing is this just happen [0, [102, 0.5, 0.591, 0.529, 10, 42, 26, 6, 8, 17, 24], 1, 27, 109, 0.41100000000000003, 0.308, 0.818, 16, 48, 26, 13, 9, 9, 22] – QWERTY Feb 18 '19 at 11:09

1 Answers1

0

Ah I see your problem.

this is really what i want to do. i want to add tt1 in another list but the thing is this just happen [0, [102, 0.5, 0.591, 0.529, 10, 42, 26, 6, 8, 17, 24], 1, 27, 109, 0.41100000000000003, 0.308, 0.818, 16, 48, 26, 13, 9, 9, 22

When you add a list to another, you are simply adding the ENTIRE list as one item in the new list. Say you want to add all the values in tt1 to a made up list, tt2.

tt1= [102, 0.5, 0.591, 0.529, 10, 42, 26, 6, 8, 17, 24]
tt2= ["some", "other", "list", 6.5, 102, True]

for item in tt1[::-1]: # we insert backwards to make it appear forwards
    tt2.insert(2, item)

print(tt2)

It is hard to explain, but the reason why I reverse the list temporariy ([::-1]) is once an item is inserted, it actually becomes the index 2. If we insert again, the previous item will become index 3 and the new item index 2 - backwards. So I reverse the list, so we're adding backwards and inserting backwards - backwards + backwards = forwards

Output:

["some", "other", 102, 0.5, 0.591, 10, 42, 26, 6, 8, 17, 24, "list", 6.5, 102, True]

Simply replace the tt2 with whatever list you want to add the items to.

Community
  • 1
  • 1
PrinceOfCreation
  • 389
  • 1
  • 12