Python Forum
Printing specific values out from a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing specific values out from a dictionary
#6
As mention bye buran so is it set,then there is one more surprise.
>>> memory = {16, 8, 16, 64, 32}
>>> memory
{16, 8, 32, 64} 
Oops missing one valueđź‘€
So list/tuple would be more suited for this task,and to show an other way,Pandas do also like this kind of structure.
import pandas as pd

my_dict = {
  "Name": ["Kindle Fire", "Samsung Galaxy Tab", "Dell Streak", "Apple iPad", "Lenovo Tab"],
  "Memory": [16, 8, 16, 64, 32],
  "Processor": [2.2, 1.2, 1.8, 2.65, 2.3],
  "Cost": [199, 114.99, 59.99, 319, 129],
}

df = pd.DataFrame(my_dict)
>>> df
                 Name  Memory  Processor    Cost
0         Kindle Fire      16       2.20  199.00
1  Samsung Galaxy Tab       8       1.20  114.99
2         Dell Streak      16       1.80   59.99
3          Apple iPad      64       2.65  319.00
4          Lenovo Tab      32       2.30  129.00

>>> # Select the devices whose cost is over 150 using query
>>> selected_devices = df.query('Cost > 150')['Name']
>>> selected_devices
0    Kindle Fire
3     Apple iPad
Name: Name, dtype: object
Reply


Messages In This Thread
RE: Printing specific values out from a dictionary - by snippsat - Apr-12-2023, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 607 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  Printing out incidence values for Class Object SquderDragon 3 417 Apr-01-2024, 07:52 AM
Last Post: SquderDragon
  need to compare 2 values in a nested dictionary jss 2 970 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,227 Apr-19-2022, 07:36 AM
Last Post: JulianZ
Question How to print each possible permutation in a dictionary that has arrays as values? noahverner1995 2 1,824 Dec-27-2021, 03:43 AM
Last Post: noahverner1995
Question How to let the user add 'None' to an specific array in a dictionary? noahverner1995 4 1,874 Dec-26-2021, 10:03 AM
Last Post: noahverner1995
  Sum the values in a pandas pivot table specific columns klllmmm 1 4,771 Nov-19-2021, 04:43 PM
Last Post: klllmmm
  Getting values from a dictionary brunolelli 5 3,739 Mar-31-2021, 11:57 PM
Last Post: snippsat
  Python dictionary with values as list to CSV Sritej26 4 3,149 Mar-27-2021, 05:53 PM
Last Post: Sritej26
  Conceptualizing modulus. How to compare & communicate with values in a Dictionary Kaanyrvhok 7 4,136 Mar-15-2021, 05:43 PM
Last Post: Kaanyrvhok

Forum Jump:

User Panel Messages

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