Python Forum
how can I display only desired items?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can I display only desired items?
#3
(Dec-24-2021, 10:01 PM)BashBedlam Wrote: Is this what you're looking for?
products = ['id', 'name', 'producer','category','price', 'stock']
 
list1 = [
	{
		"id": "1",
		"name": "predator",
		"producer": "acer",
		"category": "laptop",
		"price": 1000,
		"stock": 5
	},
	{
		"id": "2",
		"name": "monitor1",
		"producer": "dell",
		"category": "monitor",
		"price": 500,
		"stock": 10
	}
]
 
product_name = input('Enter the name of product: ')
 
for el in list1:
	if el ['name'] == product_name :
		for key, value in el.items () :
			if key != 'name' :
				print (key, value)

yes, it's perfect

thanks!
Reply


Messages In This Thread
how can I display only desired items? - by 3lnyn0 - Dec-24-2021, 09:32 PM
RE: how can I display only desired items? - by 3lnyn0 - Dec-24-2021, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 50,708 May-06-2023, 08:14 AM
Last Post: pramod08728
  Json filter is not capturing desired key/element mrapple2020 1 1,967 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  ERROR: importing desired module mbgamer28 0 2,098 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  Not rounding to desired decimal places? pprod 2 3,298 Mar-05-2021, 11:11 AM
Last Post: pprod
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 3,025 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Why this code not getting desired output ? MDRI 2 3,322 Sep-18-2020, 02:11 AM
Last Post: MDRI
  showing only desired part of a plot grknkilicaslan 1 3,502 Jul-10-2020, 03:51 PM
Last Post: Marbelous
  [Beginner] Code is not producing desired result fakej171 2 3,279 Mar-21-2020, 10:26 AM
Last Post: buran
  Not Getting the Desired value using json.dumps saurabh210 0 2,010 Feb-03-2020, 06:48 PM
Last Post: saurabh210
  Code isn't working in several IDE's when other people are getting desired output. SuperSymmetry 1 3,060 Jul-22-2017, 07:03 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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