Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i print only one item for example i need to print only 'data1'


here is code:

test_list = [{'data1':1,"data2":2,"data3":3}]

for item in test_list:
print(item)

What I have tried:

i searched everything nothing i can find :(
Posted
Updated 28-Apr-18 10:38am

1 solution

Why not use a dictionary. For example
Python
test_list = {'data1':1,"data2":2,"data3":3}
print(test_list['data1'])
 
Share this answer
 
Comments
Member 13802982 28-Apr-18 18:09pm    
yeah its a good fix but what about data type like this
i want to access 'formatted_address' and print only one
my code prints each line for every word

[{'address_components': [{'long_name': '4', 'short_name': '4', 'types': ['street_number']}, {'long_name': 'Shalva Nutsubidze Street', 'short_name': 'Shalva Nutsubidze St', 'types': ['route']}, {'long_name': 'Vake-Saburtalo', 'short_name': 'Vake-Saburtalo', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['locality', 'political']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'Georgia', 'short_name': 'GE', 'types': ['country', 'political']}], 'formatted_address': '4 Shalva Nutsubidze St, Tbilisi, Georgia', 'geometry': {'location': {'lat': 41.72973349999999, 'lng': 44.7580272}, 'location_type': 'ROOFTOP', 'viewport': {'northeast': {'lat': 41.7310824802915, 'lng': 44.7593761802915}, 'southwest': {'lat': 41.7283845197085, 'lng': 44.7566782197085}}}, 'partial_match': True, 'place_id': 'ChIJ7ey6OuJyREARM4xvXkWBxS8', 'types': ['premise']}, {'address_components': [{'long_name': '4', 'short_name': '4', 'types': ['street_number']}, {'long_name': 'Shalva Nutsubidze Street', 'short_name': 'Shalva Nutsubidze St', 'types': ['route']}, {'long_name': 'Gldani-Nadzaladevi', 'short_name': 'Gldani-Nadzaladevi', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['locality', 'political']}, {'long_name': 'Mtskheta-Mtianeti', 'short_name': 'Mtskheta-Mtianeti', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'Georgia', 'short_name': 'GE', 'types': ['country', 'political']}], 'formatted_address': '4 Shalva Nutsubidze St, Tbilisi, Georgia', 'geometry': {'bounds': {'northeast': {'lat': 41.8292626, 'lng': 44.79762059999999}, 'southwest': {'lat': 41.8292084, 'lng': 44.7975494}}, 'location': {'lat': 41.8292286, 'lng': 44.7975918}, 'location_type': 'ROOFTOP', 'viewport': {'northeast': {'lat': 41.8305844802915, 'lng': 44.7989339802915}, 'southwest': {'lat': 41.8278865197085, 'lng': 44.7962360197085}}}, 'partial_match': True, 'place_id': 'ChIJb2I7LLZuREARGpHCk8lknY0', 'types': ['premise']}, {'address_components': [{'long_name': '4', 'short_name': '4', 'types': ['street_number']}, {'long_name': 'Giorgi Dzotsenidze Street', 'short_name': 'Giorgi Dzotsenidze St', 'types': ['route']}, {'long_name': 'Vake-Saburtalo', 'short_name': 'Vake-Saburtalo', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['locality', 'political']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'Georgia', 'short_name': 'GE', 'types': ['country', 'political']}], 'formatted_address': '4 Giorgi Dzotsenidze St, Tbilisi, Georgia', 'geometry': {'bounds': {'northeast': {'lat': 41.7283584, 'lng': 44.732624}, 'southwest': {'lat': 41.7282167, 'lng': 44.732329}}, 'location': {'lat': 41.72829429999999, 'lng': 44.7324593}, 'location_type': 'ROOFTOP', 'viewport': {'northeast': {'lat': 41.72963653029149, 'lng': 44.7338254802915}, 'southwest': {'lat': 41.72693856970849, 'lng': 44.7311275197085}}}, 'partial_match': True, 'place_id': 'ChIJFXMGwAhzREARIbazVQLeyPs', 'types': ['establishment', 'point_of_interest', 'premise']}, {'address_components': [{'long_name': '4', 'short_name': '4', 'types': ['street_number']}, {'long_name': 'Ermile Bedia Street', 'short_name': 'Ermile Bedia St', 'types': ['route']}, {'long_name': 'Vake-Saburtalo', 'short_name': 'Vake-Saburtalo', 'types': ['political', 'sublocality', 'sublocality_level_1']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['locality', 'political']}, {'long_name': 'Tbilisi', 'short_name': 'Tbilisi', 'types': ['administrative_area_level_1', 'political']}, {'long_name': 'Georgia', 'short_name': 'GE', 'types
Wendelius 29-Apr-18 0:47am    
If you need to use the list, then have a try with

for item in test_list:
print(item['formatted_address'])

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900