Iterate over all key/value pairs in the order they occur in the file.
 This is *not* sorted or insertion order.

 +each+ will yield each key,value pair separately even when a key is
 duplicate.
170525
def each
      pos = hash_size
      hoff0 = @hashes[0]
      while pos < hoff0
        key, value = *read_entry(pos)
        yield(key,value)
        pos += key.length + value.length + hashref_size
      end
    end
50241
def _iter(self):
        
        keys = self.keys()
        while keys:
            key = keys[0]
            yield key
            keys = keys[1:]
1020735
def iteritems(cls):
        
        for key in dir(cls):
            val = getattr(cls, key)
            if isinstance(cls, val):
                yield (key, val)
1091539
def handle_duplications(file_path):
    
    logging.info('Handling duplications for "%s"', file_path)
    f = open_strings_file(file_path, "r+")
    header_comment_key_value_tuples = extract_header_comment_key_value_tuples_from_file(f)
    file_elements = []
    section_file_elements = []
    keys_to_objects = {}
    duplicates_found = []
    for header_comment, comments, key, value in header_comment_key_value_tuples:
        if len(header_comment) > 0:
            # New section - Appending the last section entries, sorted by comment
            for elem in sorted(section_file_elements, key=lambda x: x.comments[0]):
                file_elements.append(elem)
            section_file_elements = []
            file_elements.append(Comment(header_comment))

        if key in keys_to_objects:
            keys_to_objects[key].add_comments(comments)
            duplicates_found.append(key)
        else:
            loc_obj = LocalizationEntry(comments, key, value)
            keys_to_objects[key] = loc_obj
            section_file_elements.append(loc_obj)

    # Adding last section
    for elem in sorted(section_file_elements, key=lambda x: x.comments[0]):
        file_elements.append(elem)

    f.seek(0)

    for element in file_elements:
        f.write(unicode(element))
        f.write(u"\n")

    f.truncate()
    f.close()

    logging.info("Omitted %d duplicates (%s)" % (len(duplicates_found), ",".join(duplicates_found)))
    logging.info('Finished handling duplications for "%s"', file_path)
1353085
def get_value(self, key, default=None):
        
        def unique(seq, idfun=None):
            if idfun is None:
                def idfun(x):
                    return x
            # order preserving
            seen = {}
            result = []
            for item in seq:
                marker = idfun(item)
                if marker in seen:
                    continue
                seen[marker] = 1
                result.append(item)
            return result
        lst = self._settings.value('recent_files/%s' % key, default)
        # emtpy list
        if lst is None:
            lst = []
        # single file
        if isinstance(lst, str):
            lst = [lst]
        return unique([os.path.normpath(pth) for pth in lst])
950629
def _iterate(self, data, expanded_data):
        
        for attribute in SOURCE_KEYS:
            for k, v in data[attribute].items():
                if k == None:
                    group = 'Sources'
                else:
                    group = k
                if group in data[attribute].keys():
                    self._expand_data(data[attribute][group], expanded_data, group)
        for k, v in data['include_files'].items():
            if k == None:
                group = 'Includes'
            else:
                group = k
            self._expand_data(data['include_files'][group], expanded_data, group)

        # sort groups
        expanded_data['groups'] = OrderedDict(sorted(expanded_data['groups'].items(), key=lambda t: t[0]))
315591
function eachFrom(keys, key, iter) {
  var i = keys.indexOf(key)
  if(!~i) return
  //start at 1 because we want to visit all keys but key.
  for(var j = 1; j < keys.length; j++)
    if(iter(keys[(j+i)%keys.length], j))
      return
}
1284222
def iteritems(self):
        
        sorted_data = sorted(self.data.iteritems(), self.cmp, self.key,
                             self.reverse)
        for k,v in sorted_data:
            yield k,v
411608
def iter(self):
        
        for _file in self._files:
            with asHandle(_file) as fp:
                # Use FastqGeneralIterator because it provides access to
                # the unconverted quality string (i.e., it doesn't try to
                # figure out the numeric quality values, which we don't
                # care about at this point).
                for sequenceId, sequence, quality in FastqGeneralIterator(fp):
                    yield self.readClass(sequenceId, sequence, quality)
1014795
def od_reorder_keys(od, keys_in_new_order): # not used
    '''
    
    '''
    if set(od.keys()) != set(keys_in_new_order):
        raise KeyError('Keys in the new order do not match existing keys')
    for key in keys_in_new_order:
        od[key] = od.pop(key)
    return od
374375
def find_duplicate_keys(data):
    
    out_dict = {}
    for key, value in data:
        if key in out_dict:
            raise ValueError("Duplicate key: {}".format(key))
        out_dict[key] = value
    return out_dict
659519
def iteritems(self):
        ''''''
        for x in range(len(self.keys)):
            yield (self.keys[x], self.values[x])
67274
def iter_file_commands(self):
        
        while True:
            line = self.next_line()
            if line is None:
                break
            elif len(line) == 0 or line.startswith(b'#'):
                continue
            # Search for file commands in order of likelihood
            elif line.startswith(b'M '):
                yield self._parse_file_modify(line[2:])
            elif line.startswith(b'D '):
                path = self._path(line[2:])
                yield commands.FileDeleteCommand(path)
            elif line.startswith(b'R '):
                old, new = self._path_pair(line[2:])
                yield commands.FileRenameCommand(old, new)
            elif line.startswith(b'C '):
                src, dest = self._path_pair(line[2:])
                yield commands.FileCopyCommand(src, dest)
            elif line.startswith(b'deleteall'):
                yield commands.FileDeleteAllCommand()
            else:
                self.push_line(line)
                break
335650
def has_duplicates(self):
        
        for n in getattr(self.__kcount, _iter_values)():
            if n != 1:
                return True

        def dict_recurse(obj):
            for v in getattr(obj, _iter_values)():
                if isinstance(v, VDFDict) and v.has_duplicates():
                    return True
                elif isinstance(v, dict):
                    return dict_recurse(v)
            return False

        return dict_recurse(self)
622914
def collate(*iterables, **kwargs):
    
    key = kwargs.pop('key', lambda a: a)
    reverse = kwargs.pop('reverse', False)
    min_or_max = max if reverse else min

    rows = [iter(iterable) for iterable in iterables if iterable]
    next_values = {}
    by_key = []

    def gather_next_value(row, index):
        try:
            next_value = next(row)
        except StopIteration:
            pass
        else:
            next_values[index] = next_value
            by_key.append((key(next_value), index))

    for index, row in enumerate(rows):
        gather_next_value(row, index)

    while by_key:
        key_value, index = min_or_max(by_key)
        by_key.remove((key_value, index))
        next_value = next_values.pop(index)
        yield next_value
        gather_next_value(rows[index], index)
665387
def pairwise(iterable):
    
    it = iter(iterable)
    a = next(it, None)

    for b in it:
        yield (a, b)
        a = b
1350926
def _write_iterate(self, values):
        """"""
        result = []
        for key in self.order:
            result.append(self.lines[key].write(values))

        if len(result) > 1:
            return result
        else:
            return result[0]