Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dont know How
#1
Hi
A bash script helper create a file for my python script posted here

The 24_hour file is some thing like this:

24_hour:
ETH:100
ZEN:100
ZEC:99
DGB:45
ETH:100
ZEN:102
ZEC:93
DGB:44
ZEN:102
ZEN:104
ZEN:105
ZEN:102
ZEN:106
ZEN:108
ZEN:125
ZEN:132
ZEN:135
ZEN:105
DGB:44
DGB:43
DGB:42
DGB:45
DGB:47
DGB:48
DGB:87
DGB:156
ZEC:93
ZEC:193
ZEC:123
ZEC:126
ZEC:153
ZEC:134
ZEC:167
I need to get average of each tag and write to a new file named 24_average
So the 24_average become like this :

24_average:
ZEN:150
ZEC:95
DGB:45
ETH:100
Have no idea how to do it
Any one can help me please.
Reply
#2
1.open the file in read mode
2. create empty dict (hint: use defaultdict from collections).
3. iterate over lines of the file and parse each line and add the information to the dict created in 2
4. Once the file has been read in the dict - open new file in write mode, calculate average for each key and write to new file
Reply
#3
Thanks a lot buran
will do it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I dont know why my function won't work? MehHz2526 3 1,197 Nov-28-2022, 09:32 PM
Last Post: deanhystad
  Something the code dont work AlexPython 13 2,242 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  why I dont get any output from this code William369 2 1,126 Jun-23-2022, 09:18 PM
Last Post: William369
  [split] import PIL dont work vedansh 1 2,085 Mar-29-2020, 10:00 AM
Last Post: Larz60+
  import PIL dont work rodink 14 12,897 Feb-22-2020, 08:48 PM
Last Post: snippsat
  I dont understand bytes in python. blackknite 3 4,014 Oct-02-2019, 07:39 PM
Last Post: Gribouillis
Exclamation Get syntax error. Dont understand why beLIEve 21 14,650 Aug-25-2019, 02:28 PM
Last Post: ThomasL
  Tests are not running .Dont why shankar 3 6,329 Sep-20-2018, 07:06 AM
Last Post: shankar
  Code dont work FrankWhite 11 6,264 Mar-31-2018, 09:07 PM
Last Post: FrankWhite

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020