Note that there are some explanatory texts on larger screens.

plurals
  1. POspecific implementation of dictionary
    primarykey
    data
    text
    <p>I don't know if the title is apt, but for the time being this is my question:</p> <p>I have entries in text file(which has 2 columns) in the following format: </p> <pre><code>Name Time Santa 1.2 Jim 2.5 Santa 2.7 Santa 2.9 </code></pre> <p>I should form a dictionary which has Name as the key, (Time, Count) as the value. In the above names, Santa repeated 3 times and the time difference of consecutive occurances is less than 2 seconds. So the Count value associated with that entry is 3. If such case occurs, that entry should be deleted from dictionary. Otherwise, count value should be zero (If the 2 occurances of Santa happened 2 seconds apart and 3rd occurance happened after 2 seconds, then count is reinitialized to zero for that entry). </p> <p>Can this be implemented like this: Make the (Time, Count) as the list and make that list as the values to the keys? I am a newbie to Python, please excuse any mistakes.</p> <p>The pseudocode is something like this:</p> <pre><code>Read line in the file: if Santa is in dictionary: time_difference = time from column 2 of the line - dictionary[Santa] if(time_difference &lt; 2): Replace the old occurance with new one along with time # If the previous count value associated with Santa = 1, add 1 to make it 2 Make the Count associated with Santa = count+1 if(count associated with Santa = 3): delete the Santa entry else: Make count associated with Santa = 1 else: Add Santa to dictionary along with its time and make associated count = 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload