[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Mar 24 11:41:45 EDT 2022


On Wed, 23 Mar 2022 20:54:01 +0100, <marcus.luetolf at bluewin.ch> declaimed
the following:

>Hello Experts,
>I tried to follow your advises logically think over my  task and set up an algorithm as sort of pseudocode below.
>Before doing coding I'd like to present it for critisism:
>
>>players_list = list('abcdefghijklmnop')
>

	And again you are back to where the only data structure to be used for
everything is a LIST.

	Keep your players as a string. Think of your "team" as a unit, made out
of a string.

	Strings are indexable -- the syntax looks just like what you'd use with
a list of 1-char strings).

>>> import sys
>>> import string
>>> pch = string.ascii_lowercase[:16]
>>> plst = list(pch)
>>> pch
'abcdefghijklmnop'
>>> plst
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p']
>>> sys.getsizeof(pch)
65
>>> sys.getsizeof(plst)
184
>>> 

(as strings, the storage is also a third of the list)

>>for day_1 :
>>° create 4 lists named team_lists, containing 4 subsequent letters/players
>>	by iterating over every 4th letter/player
>>	identifying its indices in players_list (0, 4, 8, 12)
>>             list/print  team_lists of 4 subsequent Letters/elements each starting
>>                  at every 4th letter/player in players_list
>>° assign all 4 letter/player of  the first team lists as lead_player (‘a’, ‘b’, ‘c’, ‘d’)

	Since you are defining a on-off process, and not something programmatic
(that is -- there is nothing in the above that can be CHANGED from run to
run), you might as well hard-code this step.

>>> day1 = [ pch[0:4], pch[4:8], pch[8:12], pch[12:16] ]
>>> day1
['abcd', 'efgh', 'ijkl', 'mnop']
>>> 



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list