python - Grab items from dictionary based on length of lists they are mapped to -


तो मेरे पास dict है, जिसमें निम्न प्रारूप है

  डी = {1: [एम 1, एम 2], 2: [एम 3, एम 5, एम 6], 3: [एम 4], 4: [एम 7, एम 8]}  

मैं जानकारी को बाहर खींचने के लिए जब मैं सबसे बड़ी सूचियों को पहले मिल के माध्यम से फिर से करना चाहते हैं। लेकिन क्योंकि शब्दकोशों में असाधारण भंडारण नहीं होता है जब मैं ऐसा करता हूं

  के लिए n, my_list in d.items (): # do stuff ..  

मैं कर सकता हूँ 'गारंटी नहीं है कि मुझे 2: [एम 3, एम 5, एम 6] एंट्री मिल जाएगी। क्या ऐसा करने का एक साफ तरीका है?

आपको बस आइटम की लंबाई मान।

  आइटम = सॉर्ट किया गया (डी.इटम्स (), कुंजी = लैम्ब्डा आई: लेन (आई [1]), रिवर्स = ट्रू)  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -