Python Forum
Looping through a dictionary for every other value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping through a dictionary for every other value
#6
Communication with functions should be done via argument passing and return values. Not global variables.
from string import ascii_lowercase as lower


def string_to_dict():
    return dict(zip(range(1,27), lower))


def odds_only():
    my_dict = string_to_dict()
    return {k:v for k,v in my_dict.items() if k % 2}


print(odds_only())
Reply


Messages In This Thread
RE: Looping through a dictionary for every other value - by Mekire - Jan-25-2018, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Looping to Create Nested Dictionary gngu2691 10 33,957 Jun-22-2018, 04:11 PM
Last Post: anickone

Forum Jump:

User Panel Messages

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