Re: [Tutor] Tutor Digest, Vol 166, Issue 21

2017-12-24 Thread anish singh
>> However, I am stuck. I have below code which is not working. I don't know how to achieve this programmatically: sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted alphabetically (in an ascending order). > > Define "not

[Tutor] sort by value and then by key

2017-12-24 Thread anish singh
document = "Practice makes perfect. you'll only get Perfect by practice. just practice!" output: [ ["practice", "3"], ["perfect", "2"], ["by", "1"], ["get", "1"], ["just", "1"], ["makes", "1"], ["only", "1"], ["youll", "1"] ] I am supposed to

[Tutor] Python creating trie

2017-11-12 Thread anish singh
Can someone explain me this code to create a trie from words? import collections words = ["bad", "sad", "abyss"] Trie = lambda: collections.defaultdict(Trie) trie = Trie() END = True for i, word in enumerate(words): reduce(dict.__getitem__, word, trie)[END] = i print(trie.values()) I am

Re: [Tutor] Tutor Digest, Vol 160, Issue 34

2017-06-27 Thread anish singh
> >> anish singh wrote: > >> > >>> I need a custom comparator. > >>> > >>> dictionary = {a:[b,c], d:[e,f]} > >>> > >>> If both 'b' and 'e' belong to the same bin > >>> then it should be compared based on

[Tutor] custom comparator with ordered list

2017-06-26 Thread anish singh
I need a custom comparator. dictionary = {a:[b,c], d:[e,f]} If both 'b' and 'e' belong to the same bin then it should be compared based on 'c' and 'f'. However, I want to also represent the result of the sorted operation in a ordered dictionary as order is important. My custom comparator is

[Tutor] decorators in a class

2017-06-12 Thread anish singh
Trying to use decorators in my class. I am calling build_tree from the main function and i want to increment the arguments by a constant factor by using decorators. However as build_tree is a recursive function, I don't want to call it recursively with increased constant factor always. Probably

[Tutor] Help with Python Queue

2016-11-26 Thread anish singh
I was just writing to read a file using popen and wanted to use queue along with it. I have below code but it is giving this error: AttributeError: Queue instance has no attribute 'taskdone' import threading from Queue import Queue def worker(q): while True: dataset = q.get()

[Tutor] python grep implementation

2016-10-13 Thread anish singh
I am trying to implement grep functionality in python. import os, sys, getopt import multiprocessing as mp import re import itertools def get_files(path, pattern): for (dirpath, dirnames, filenames) in os.walk(path): for filename in filenames: if filename.endswith(pattern):

Re: [Tutor] Tutor Digest, Vol 152, Issue 3

2016-10-02 Thread anish singh
> On 01/10/16 09:16, anish singh wrote: > > I am trying to implement grep to just increase my knowledge > > about regular expression. > > > > Below is the program usage: > > python test.py -i Documents/linux/linux/ -s '\w+_readalarm*' > > > > Howe

[Tutor] receiving regular expression from command line

2016-10-01 Thread anish singh
I am trying to implement grep to just increase my knowledge about regular expression. Below is the program usage: python test.py -i Documents/linux/linux/ -s '\w+_readalarm*' However, due to my lack of knowledge about string handling in python, I am getting wrong results. def read_file(file,

[Tutor] global interpreter lock

2016-09-15 Thread anish singh
Can someone explain global interpreter lock with some source code examples? I didn't understand explanation offered here: https://docs.python.org/3/glossary.html#term-global-interpreter-lock ___ Tutor maillist - Tutor@python.org To unsubscribe or