dictionary - Python- within a for loop, select item from a list within a list of list -
sorry if code bad hobbyist... done in python 3.6. cat_lists list of lists = [['1','etc1],['a', 'etc']]. beneath function called print_cat_data() after creation of var_names , cat_lists.
def print_cat_data(var_names): #print out tables of data, using lists startup_cat. using i/o fix open("cat_table.txt","w")as cat_table: item_a, item_b in zip (var_names, cat_lists): #need select items cat_lists therefore need select individual items cat_table.write(str(item_a) + ": " + '[%s]' % ', '.join(map(str, item_b)) + "\n") open ("cat_table.txt","r")as cat_table: print(cat_table.read())
under for/zip
statement want select list in cat_lists
, print out items in list (not print list).
- problem 1:
map
returns list.. - problem 2: nesting items in list in list in loop etc...
currently writes:
name (item var_names): [['joe', 'ben']] (list cat_lists) age: [['2', '33']]
should write
name (item var_names):'joe', 'ben' (items list in list cat_lists) age: [['2', '33']]
Comments
Post a Comment