Python Forum
AttributeError: 'list' object has no attribute 'values'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'list' object has no attribute 'values'
#2
The error is from trying to access a list like a dict.

you can use the list index to access the data or loop the list to get the data.

com_str = [{'community_string': 'public'}, {'community_string': 'private'}]

print('list index')
print(f"{com_str[0]['community_string']} | {com_str[1]['community_string']}")

print()
print('looping')
for data in com_str:
    print(data['community_string'])

print()
print('One liner')
print('\n'.join([data['community_string'] for data in com_str]))
Output:
list index public | private looping public private One liner public private
ilknurg likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
RE: AttributeError: 'list' object has no attribute 'values' - by menator01 - Jan-19-2022, 08:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out incidence values for Class Object SquderDragon 3 333 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  Copying the order of another list with identical values gohanhango 7 1,212 Nov-29-2023, 09:17 PM
Last Post: Pedroski55
  Search Excel File with a list of values huzzug 4 1,309 Nov-03-2023, 05:35 PM
Last Post: huzzug
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 825 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,831 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,615 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 800 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 4,042 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 783 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  Comparing List values to get indexes Edward_ 7 1,240 Jun-09-2023, 04:57 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020