Python Forum
Trying to print corresponding elements in two different list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to print corresponding elements in two different list
#3
(Mar-03-2020, 01:39 AM)Larz60+ Wrote: You can zip the two lists, Example:
>>> rainfall = [1.1, 2.3, .5, 2, 3.1, .25, 1.1, 2.3, .5, 2, 3.1, .25]
>>> months = ['January', 'February', 'March', 'April', 'May', 
...          'June','July', 'August', 'September', 'October', 'November', 'December']
>>> rpt = zip(months, rainfall)
>>> for month, rainamt in rpt:
...     print(f"Month: {month}, rainfall: {rainamt}")
... 
Month: January, rainfall: 1.1
Month: February, rainfall: 2.3
Month: March, rainfall: 0.5
Month: April, rainfall: 2
Month: May, rainfall: 3.1
Month: June, rainfall: 0.25
Month: July, rainfall: 1.1
Month: August, rainfall: 2.3
Month: September, rainfall: 0.5
Month: October, rainfall: 2
Month: November, rainfall: 3.1
Month: December, rainfall: 0.25

i am fine with printing the month and amount for each month. i am having issues trying to print the max rainfall with its corresponding month attached.
Reply


Messages In This Thread
RE: Trying to print corresponding elements in two different list - by Darthmarvolo - Mar-03-2020, 01:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 505 Jan-27-2024, 04:03 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 521 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  How do you get Python to print just one value in a list? 357mag 3 1,059 May-17-2023, 09:52 PM
Last Post: rob101
  Checking if a string contains all or any elements of a list k1llcod3 1 1,160 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  How to change the datatype of list elements? mHosseinDS86 9 2,058 Aug-24-2022, 05:26 PM
Last Post: deanhystad
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,257 May-17-2022, 11:38 AM
Last Post: Larz60+
  Print List to Terminal DaveG 2 1,482 Apr-02-2022, 11:25 AM
Last Post: perfringo
  Why am I getting list elements < 0 ? Mark17 8 3,227 Aug-26-2021, 09:31 AM
Last Post: naughtyCat
  Looping through nested elements and updating the original list Alex_James 3 2,187 Aug-19-2021, 12:05 PM
Last Post: Alex_James
  Extracting Elements From A Website List knight2000 2 2,356 Jul-20-2021, 10:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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