-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I iterate over Dictionary values? #8
Comments
Currently As from iterfzf import iterfzf
def fzf_dict(d, multi):
options = ('{0}\t{1}'.format(k, v) for k, v in d.items())
for kv in iterfzf(options, multi=multi):
yield kv[:kv.index('\t')]
def main():
d = {
'1': 'foo',
'2': 'bar',
'3': 'spam',
'4': 'egg',
}
print(iterfzf(d.values()))
keys = fzf_dict(d, multi=True)
for key in keys:
print(repr(key), '=>', repr(d[key]))
if __name__ == '__main__':
main() The above code assumes keys must have no tabs, hence
I believe |
Ahh thank you very much for explanation. Should we add this into the documentation as well? It will come in very handy. Are we planning to change it in anyways in near future? |
I believe the limitation (that it takes only strings) should be fixed in the upstream |
I mean the workaround for these, like the one you just suggested to me. imho this is fantastic I will definitely want to see more of the development :D |
Okay, I added the example code into the repository's examples/ directory: Lines 1 to 34 in 2d13fdf
|
So basically I have a dictionary
I would like to be able to search through foo,bar etc and return the corresponding id. Even If I could get the key and value both of selection, that'd be fine as well.
I have tried following:
iterfzf(d,multi=True) which basically allows me to select the keys as dictionaries are iterable over keys.
then
iterfzf(d.values(),multi=True) shows nothing else other than 0 0 and exits without any errors
iterfzf(d.items(),multi=True) shows some weird behaviour and error as follows:
It shows the error in exact disoriented manner.
I would like to know the correct way to achieve the desired result as well as once specified would go ahead and make the pr with appropriate inclusion in documentation. Thank you for this awesome module and for your generous time.
using d.iteritems gives following Error:
EDIT: Added the iteritems error
The text was updated successfully, but these errors were encountered: