0
tbl_headers = db_admin.execute("SELECT name, type FROM PRAGMA_TABLE_INFO(?);", table_name)

tbl_headers is same below:

[{'name': 'id', 'type': 'INTEGER'}, {'name': 'abasdfasd', 'type': 'TEXT'}, {'name': 'sx', 'type': 'TEXT'}, {'name': 'password', 'type': 'NULL'}, {'name': 'asdf', 'type': 'TEXT'}]

I need apply hash_in() function on the 'name' values are in dictionary elements of above list.

Have tried these:

tbl_headers = [hash_in(i['name']) for i in tbl_headers]

suppresses dictionaries and return only a list of 'name' values:

['sxtw001c001h', 'sxtw001c001r001Z001e001c001r001Z001a001Z', 'sxtw001w001r', 'sxtw001c001q001n001v001r001r001Z001o', 'sxtw001e001c001r001Z']

OR

tbl_headers = map(hash_in, tbl_headers)

Returns error.

Update

The Output result I have seek is same:

[{'name': hash_in('id'), 'type': 'INTEGER'}, {'name': hash_in('abasdfasd'), 'type': 'TEXT'}, {'name': hash_in('sx'), 'type': 'TEXT'}, {'name': ('password'), 'type': 'NULL'}, {'name': ('asdf'), 'type': 'TEXT'}]

Appreciate you.

parmer_110
  • 325
  • 2
  • 11
  • Can you give us an example of the output/end result you seek? – JonSG Jan 18 '23 at 16:38
  • What's the error ? – Maurice Meyer Jan 18 '23 at 16:42
  • @MauriceMeyer: `` (No results more this!) – parmer_110 Jan 18 '23 at 16:46
  • Since you are looking to update the dictionaries, I would be strongly tempted to just use a traditional `for` loop. – JonSG Jan 18 '23 at 16:46
  • @JonSG, As python strange availability are there, is there possible simple and more straight way to run function with situational on the intended dictionary items are wrapped in a list? I though may have some notations in map() or comprehensions or lambda functions. – parmer_110 Jan 18 '23 at 16:50
  • Do you want to modify the original list/list items or do you want to create a new list and or new items? – JonSG Jan 18 '23 at 17:03
  • @parmer_110: That's how [map](https://docs.python.org/3/library/functions.html#map) works in Python3, that's not an error. – Maurice Meyer Jan 18 '23 at 17:18

1 Answers1

1

Try this list comprehension:

tbl_headers = [{'name': hash_in(i['name']), 'type': i['type']} for i in tbl_headers]
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34