vesh = [dct[bots[l]][s]['m'],dct[bots[l]][s]['p']] name = ''.join(vesh[0]) price = ''.join(vesh[1]) weapon = name + price 

TypeError: can only join an iterable

why?

  • Telepaths on vacation, provide specific data that is stored in vesh. - Alex Krass
  • five
    join(iterable) expects an object that supports iteration as an argument - the error itself is what exactly this says - MaxU
  • @MaxU maybe post the answer? - Nick Volynkin
  • Can try ( dct [bots [l]] [s] ['m'], dct [bots [l]] [s] ['p'] ) ? Per square space [] - And
  • @NickVolynkin, I posted a response with examples of iterated objects - MaxU

1 answer 1

str.join (iterable) expects as an argument iterable - an object that supports iteration .

An item capable of returning it at one time. Examples of iterables include all sequence types ( list __iter__() or __getitem__() method. It is needed ( zip() , map() , ...). When an iterable object is used, it returns an iterator to the object. This iterator is over for the set of values. When using iterables, it is usually not necessary to call iter() or deal with the iterator objects yourself. The statement for the statement is a statement. See also iterator , sequence , and generator .

in simple in Russian (c) @jfs :

''.join() takes a composite object — a collection of strings, such as a list, which you can pass in a for-loop to bypass all strings

Here is one way to determine if an object is iterable and at the same time examples of objects to be iterated:

 In [1]: import collections In [2]: isinstance(['a','b'], collections.Iterable) Out[2]: True In [3]: isinstance('ab', collections.Iterable) Out[3]: True In [4]: isinstance('a', collections.Iterable) Out[4]: True In [5]: isinstance([1,2], collections.Iterable) Out[5]: True In [6]: isinstance(1, collections.Iterable) Out[6]: False # NOT iterable In [7]: isinstance((1), collections.Iterable) Out[7]: False # NOT iterable In [8]: isinstance((1,), collections.Iterable) Out[8]: True In [9]: isinstance({'a':'b'}, collections.Iterable) Out[9]: True In [10]: isinstance({}, collections.Iterable) Out[10]: True In [11]: isinstance(set([1]), collections.Iterable) Out[11]: True In [12]: isinstance(set(), collections.Iterable) Out[12]: True In [13]: isinstance(open('d:/temp/aaa.txt', 'w'), collections.Iterable) Out[13]: True 
  • for simplicity, we can say that ''.join takes a composite object — a collection of strings, such as a list, which you can pass in a for-loop to bypass all strings. - jfs
  • @jfs, thank you, better not tell - added in response in the form of a quote - MaxU