osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

My pseudocode to Python?


Rather than starting with all seven strings in the list and deleting one if
a conditional is not true, why not start with 6 elements (with the one in
index 3 missing) and insert the 7th element into the third index?

>>> mylist = ['a', 'b', 'c', 'e', 'f', 'g']
>>> if x:
>>>    mylist.insert(3, 'd')

>>> mylist
['a', 'b', 'c', 'd', 'e', 'f', 'g']


Regards,
Kyle Stanley (aeros167)


On Mon, Aug 19, 2019 at 2:30 PM Rob Gaddi <rgaddi at highlandtechnology.invalid>
wrote:

> On 8/19/19 10:43 AM, Stefan Ram wrote:
> >    Can someone kindly translate my pseudocode to terse Python:
> >
> > list = \
> > [ 'afaueghauihaiuhgaiuhgaiuhgaeihui',
> >    'erghariughauieghaiughahgaihgaiuhgaiuh',
> >    'rejganregairghaiurghaiuhgauihgauighaei',
> >    if x: 'argaeruighaiurhauirguiahuiahgiauhgaeuihi',
> >    'reiugaheirughauierhgauiaeihauiehgiuaehuih'
> >    'ejiaeigaiuegreaiugheiugheaiughauighaiughaiu'
> >    'egairughauirghauiruiegihgruiehgiuaehgiaue' ]
> >
> >    ? I want the list to have the seven strings shown as entries
> >    if bool(x) is True, but otherwise the list should only have
> >    six entries - without the entry directly behind "if x: ".
> >
> >
>
> mylist = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
> if not x:
>     del mylist[3]
>
>
> --
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.
> --
> https://mail.python.org/mailman/listinfo/python-list
>