Python Forum
making list in looping a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making list in looping a dictionary
#1
how to make a list out of this ?
is this the right approach?
users={"glenn":1,"elena":2,"mama":3}
names=(list(users.keys()))
for i in names:
    # i should become a list of each 3 keys in a dictionay

    print(type(i)) # output = <class 'list'>
my goal is something like this:
looping a dictionary and making a list of each every keys
users={"glenn":1,"elena":2,"mama":3}
names=(list(users.keys()))
for i in names: # for each ? i dont know what is the correct approach of this
    # i should become a list of each 3 keys in a dictionay
    i=list(i)
    print(type(i))
print(type(glenn)) # confirming if its a list but, i think its impossible coz its outside of the for loop
I only want to loop the dictionary to get each keys as list item
Reply


Messages In This Thread
making list in looping a dictionary - by glennford49 - Jun-25-2020, 09:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary in a list bashage 2 560 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 695 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 496 Oct-27-2023, 03:03 PM
Last Post: buran
  for loops break when I call the list I'm looping through Radical 4 903 Sep-18-2023, 07:52 AM
Last Post: buran
  How to add list to dictionary? Kull_Khan 3 1,012 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  check if element is in a list in a dictionary value ambrozote 4 1,986 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 1,975 Apr-28-2022, 06:59 AM
Last Post: buran
  how to assign items from a list to a dictionary CompleteNewb 3 1,592 Mar-19-2022, 01:25 AM
Last Post: deanhystad
  Python, how to manage multiple data in list or dictionary with calculations and FIFO Mikeardy 8 2,616 Dec-31-2021, 07:47 AM
Last Post: Mikeardy
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,927 Oct-03-2021, 05:16 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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